postgresql/src/backend/commands
Tom Lane c1d9579dd8 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:39 -04:00
..
aggregatecmds.c Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
alter.c Try to acquire relation locks in RangeVarGetRelid. 2011-07-08 22:19:30 -04:00
analyze.c Fix thinko in previous patch to always update pg_class.reltuples/relpages. 2011-06-19 14:00:48 -04:00
async.c Preserve caller's memory context in ProcessCompletedNotifies(). 2011-05-27 12:10:32 -04:00
cluster.c Remove extra copying of TupleDescs for heap_create_with_catalog 2011-06-20 10:50:23 -04:00
collationcmds.c Remove rel.h from objectaddress.h; only relcache.h is necessary. 2011-06-28 17:08:29 -04:00
comment.c Remove rel.h from objectaddress.h; only relcache.h is necessary. 2011-06-28 17:08:29 -04:00
constraint.c Move Trigger and TriggerDesc structs out of rel.h into a new reltrigger.h 2011-07-04 14:35:58 -04:00
conversioncmds.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
copy.c Move Trigger and TriggerDesc structs out of rel.h into a new reltrigger.h 2011-07-04 14:35:58 -04:00
dbcommands.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
define.c Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
discard.c Refactor the executor's API to support data-modifying CTEs better. 2011-02-27 13:44:12 -05:00
explain.c Move Trigger and TriggerDesc structs out of rel.h into a new reltrigger.h 2011-07-04 14:35:58 -04:00
extension.c Fix another oversight in logging of changes in postgresql.conf settings. 2011-07-08 17:02:58 -04:00
foreigncmds.c Call FDW validator functions even when the options list is empty. 2011-07-05 18:21:12 -04:00
functioncmds.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
indexcmds.c Try to acquire relation locks in RangeVarGetRelid. 2011-07-08 22:19:30 -04:00
lockcmds.c Try to acquire relation locks in RangeVarGetRelid. 2011-07-08 22:19:30 -04:00
Makefile DDL support for collations 2011-02-12 15:55:18 +02:00
opclasscmds.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
operatorcmds.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
portalcmds.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
prepare.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
proclang.c Core support for "extensions", which are packages of SQL objects. 2011-02-08 16:13:22 -05:00
schemacmds.c Move Trigger and TriggerDesc structs out of rel.h into a new reltrigger.h 2011-07-04 14:35:58 -04:00
seclabel.c Remove rel.h from objectaddress.h; only relcache.h is necessary. 2011-06-28 17:08:29 -04:00
sequence.c Try to acquire relation locks in RangeVarGetRelid. 2011-07-08 22:19:30 -04:00
tablecmds.c Try to acquire relation locks in RangeVarGetRelid. 2011-07-08 22:19:30 -04:00
tablespace.c pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
trigger.c Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window. 2011-07-12 18:24:39 -04:00
tsearchcmds.c Pgindent run before 9.1 beta2. 2011-06-09 14:32:50 -04:00
typecmds.c Move Trigger and TriggerDesc structs out of rel.h into a new reltrigger.h 2011-07-04 14:35:58 -04:00
user.c Add postmaster/postgres undocumented -b option for binary upgrades. 2011-04-25 12:00:21 -04:00
vacuum.c Try to acquire relation locks in RangeVarGetRelid. 2011-07-08 22:19:30 -04:00
vacuumlazy.c Make the visibility map crash-safe. 2011-06-21 23:04:40 -04:00
variable.c Pgindent run before 9.1 beta2. 2011-06-09 14:32:50 -04:00
view.c Fix bugs in relpersistence handling during table creation. 2011-07-03 17:34:47 -04:00