﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31060	Window expression are not allowed in conditional statements used only in the SELECT clause.	Mariusz Felisiak	Alex Aktsipetrov	"Django raises `NotSupportedError` when using window expressions in conditional statements used only in the `SELECT` clause, e.g.
{{{
Employee.objects.annotate(
    lag=Window(
        expression=Lag(expression='salary', offset=1),
        partition_by=F('department'),
        order_by=[F('salary').asc(), F('name').asc()],
    ),
    is_changed=Case(
        When(salary=F('lag'), then=Value(False)),
        default=Value(True), output_field=BooleanField()
    ),
)
}}}

The SQL standard disallows referencing window functions in the `WHERE` clause but in this case it's only used in the `SELECT` clause so this should be possible.

Thanks utapyngo for the report.

Regression in 4edad1ddf6203326e0be4bdb105beecb0fe454c4."	Bug	closed	Database layer (models, ORM)	3.0	Release blocker	fixed		Mads Jensen Alex Aktsipetrov Alexandr Artemyev	Accepted	1	0	0	0	0	0
