postgresql/src
Tom Lane b61b28fbe8 Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window.
Regular aggregate functions in combination with, or within the arguments
of, window functions are OK per spec; they have the semantics that the
aggregate output rows are computed and then we run the window functions
over that row set.  (Thus, this combination is not really useful unless
there's a GROUP BY so that more than one aggregate output row is possible.)
The case without GROUP BY could fail, as recently reported by Jeff Davis,
because sloppy construction of the Agg node's targetlist resulted in extra
references to possibly-ungrouped Vars appearing outside the aggregate
function calls themselves.  See the added regression test case for an
example.

Fixing this requires modifying the API of flatten_tlist and its underlying
function pull_var_clause.  I chose to make pull_var_clause's API for
aggregates identical to what it was already doing for placeholders, since
the useful behaviors turn out to be the same (error, report node as-is, or
recurse into it).  I also tightened the error checking in this area a bit:
if it was ever valid to see an uplevel Var, Aggref, or PlaceHolderVar here,
that was a long time ago, so complain instead of ignoring them.

Backpatch into 9.1.  The failure exists in 8.4 and 9.0 as well, but seeing
that it only occurs in a basically-useless corner case, it doesn't seem
worth the risks of changing a function API in a minor release.  There might
be third-party code using pull_var_clause.
2011-07-12 18:24:53 -04:00
..
backend Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window. 2011-07-12 18:24:53 -04:00
bin Fix psql's counting of script file line numbers during COPY. 2011-07-05 12:05:15 -04:00
include Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window. 2011-07-12 18:24:53 -04:00
interfaces Capitalization fixes 2011-06-19 00:39:19 +03:00
makefiles Use single quotes in preference to double quotes for protecting pathnames. 2011-06-15 21:45:50 -04:00
pl Put comments on the installable procedural languages. 2011-07-03 19:04:05 -04:00
port Unify spelling of "canceled", "canceling", "cancellation" 2011-07-02 23:30:01 +03:00
template Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
test Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window. 2011-07-12 18:24:53 -04:00
timezone Pgindent run before 9.1 beta2. 2011-06-09 14:32:50 -04:00
tools Back-patch Fix bat file quoting of %ENV from commit 19b7fac8. 2011-07-04 10:44:07 -04:00
tutorial Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Fix some oversights in distprep and maintainer-clean targets. 2011-03-10 00:04:05 -05:00
Makefile.global.in Make distprep and *clean build targets recurse into all subdirectories. 2011-07-03 13:55:27 -04:00
Makefile.shlib Use single quotes in preference to double quotes for protecting pathnames. 2011-06-15 21:45:50 -04:00
nls-global.mk Fix makefile logic to not break the build when xgettext is missing 2010-10-14 23:16:46 +03:00
win32.mak Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00