Support ORDER BY within aggregate function calls, at long last providing a

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 34d26872ed816b299eef2fa4240d55316697f42d
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2009-12-15T17:57:48Z
Releases: 9.0.0
Support ORDER BY within aggregate function calls, at long last providing a
non-kluge method for controlling the order in which values are fed to an
aggregate function.  At the same time eliminate the old implementation
restriction that DISTINCT was only supported for single-argument aggregates.

Possibly release-notable behavioral change: formerly, agg(DISTINCT x)
dropped null values of x unconditionally.  Now, it does so only if the
agg transition function is strict; otherwise nulls are treated as DISTINCT
normally would, ie, you get one copy.

Andrew Gierth, reviewed by Hitoshi Harada

Files

PathChange+/−
doc/src/sgml/func.sgml modified +26 −15
doc/src/sgml/syntax.sgml modified +47 −16
src/backend/executor/nodeAgg.c modified +358 −108
src/backend/nodes/copyfuncs.c modified +5 −3
src/backend/nodes/equalfuncs.c modified +5 −3
src/backend/nodes/nodeFuncs.c modified +14 −1
src/backend/nodes/outfuncs.c modified +5 −3
src/backend/nodes/readfuncs.c modified +4 −3
src/backend/optimizer/plan/planagg.c modified +8 −8
src/backend/optimizer/plan/planner.c modified +6 −5
src/backend/optimizer/util/clauses.c modified +10 −9
src/backend/parser/analyze.c modified +7 −6
src/backend/parser/gram.y modified +51 −5
src/backend/parser/parse_agg.c modified +89 −5
src/backend/parser/parse_clause.c modified +16 −10
src/backend/parser/parse_expr.c modified +6 −5
src/backend/parser/parse_func.c modified +27 −6
src/backend/parser/parse_utilcmd.c modified +2 −1
src/backend/utils/adt/ruleutils.c modified +20 −8
src/include/catalog/catversion.h modified +2 −2
src/include/nodes/parsenodes.h modified +5 −3
src/include/nodes/primnodes.h modified +17 −4
src/include/optimizer/clauses.h modified +2 −2
src/include/parser/parse_agg.h modified +3 −2
src/include/parser/parse_clause.h modified +4 −4
src/include/parser/parse_func.h modified +3 −2
src/test/regress/expected/aggregates.out modified +270 −0
src/test/regress/expected/create_aggregate.out modified +20 −4
src/test/regress/output/misc.source modified +2 −1
src/test/regress/sql/aggregates.sql modified +125 −0
src/test/regress/sql/create_aggregate.sql modified +24 −3