]> granicus.if.org Git - postgresql/commit
Postpone aggregate checks until after collation is assigned.
authorAndrew Gierth <rhodiumtoad@postgresql.org>
Thu, 17 Jan 2019 05:33:01 +0000 (05:33 +0000)
committerAndrew Gierth <rhodiumtoad@postgresql.org>
Thu, 17 Jan 2019 06:26:15 +0000 (06:26 +0000)
commit624046abe23f3da003b8db07d7028c70f1c672bd
tree957fa45b22da6af4856b47f52d187a36e4b99de5
parent381409686a81c2680c3d6ac416b5a9d823f6cf83
Postpone aggregate checks until after collation is assigned.

Previously, parseCheckAggregates was run before
assign_query_collations, but this causes problems if any expression
has already had a collation assigned by some transform function (e.g.
transformCaseExpr) before parseCheckAggregates runs. The differing
collations would cause expressions not to be recognized as equal to
the ones in the GROUP BY clause, leading to spurious errors about
unaggregated column references.

The result was that CASE expr WHEN val ... would fail when "expr"
contained a GROUPING() expression or matched one of the group by
expressions, and where collatable types were involved; whereas the
supposedly identical CASE WHEN expr = val ... would succeed.

Backpatch all the way; this appears to have been wrong ever since
collations were introduced.

Per report from Guillaume Lelarge, analysis and patch by me.

Discussion: https://postgr.es/m/CAECtzeVSO_US8C2Khgfv54ZMUOBR4sWq+6_bLrETnWExHT=rFg@mail.gmail.com
Discussion: https://postgr.es/m/87muo0k0c7.fsf@news-spur.riddles.org.uk
src/backend/parser/analyze.c
src/test/regress/expected/aggregates.out
src/test/regress/expected/groupingsets.out
src/test/regress/sql/aggregates.sql
src/test/regress/sql/groupingsets.sql