Fix collation assignment for aggregates with ORDER BY.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 26 Apr 2013 19:48:24 +0000 (15:48 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 26 Apr 2013 19:48:53 +0000 (15:48 -0400)
commit41a2760f611d1b3c1e67f755baf0a052b5cec9af
tree49d241ef6bf8200782c22780ecb7fdeabca6b3c3
parentb42ea7981ce1e7484951a22662937541066d8647
Fix collation assignment for aggregates with ORDER BY.

ORDER BY expressions were being treated the same as regular aggregate
arguments for purposes of collation determination, but really they should
not affect the aggregate's collation at all; only collations of the
aggregate's regular arguments should affect it.

In many cases this mistake would lead to incorrectly throwing a "collation
conflict" error; but in some cases the corrected code will silently assign
a different collation to the aggregate than before, for example
agg(foo ORDER BY bar COLLATE "x")
which will now use foo's collation rather than "x" for the aggregate.
Given this risk and the lack of field complaints about the issue, it
doesn't seem prudent to back-patch.

In passing, rearrange code in assign_collations_walker so that we don't
need multiple copies of the standard logic for computing collation of a
node with children.  (Previously, CaseExpr duplicated the standard logic,
and we would have needed a third copy for Aggref without this change.)

Andrew Gierth and David Fetter
src/backend/parser/parse_collate.c
src/test/regress/expected/collate.out
src/test/regress/sql/collate.sql