]> granicus.if.org Git - postgresql/commit
Modify the definition of window-function PARTITION BY and ORDER BY clauses
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 27 Aug 2009 20:08:12 +0000 (20:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 27 Aug 2009 20:08:12 +0000 (20:08 +0000)
commit3f2fa308d14635a3936c0b62f8f05631d6362a27
treec13330c7ff2eb7257f8d537d0d6e71e82489e724
parent6c593b9ca0fdf2cf6a451abc55002f94a6d34ed2
Modify the definition of window-function PARTITION BY and ORDER BY clauses
so that their elements are always taken as simple expressions over the
query's input columns.  It originally seemed like a good idea to make them
act exactly like GROUP BY and ORDER BY, right down to the SQL92-era behavior
of accepting output column names or numbers.  However, that was not such a
great idea, for two reasons:

1. It permits circular references, as exhibited in bug #5018: the output
column could be the one containing the window function itself.  (We actually
had a regression test case illustrating this, but nobody thought twice about
how confusing that would be.)

2. It doesn't seem like a good idea for, eg, "lead(foo) OVER (ORDER BY foo)"
to potentially use two completely different meanings for "foo".

Accordingly, narrow down the behavior of window clauses to use only the
SQL99-compliant interpretation that the expressions are simple expressions.
doc/src/sgml/ref/select.sgml
doc/src/sgml/syntax.sgml
src/backend/parser/analyze.c
src/backend/parser/parse_clause.c
src/include/parser/parse_clause.h
src/test/regress/expected/window.out
src/test/regress/sql/window.sql