]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix old bug with coercing the result of a COLLATE expression.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 12 Apr 2021 18:37:22 +0000 (14:37 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 12 Apr 2021 18:37:22 +0000 (14:37 -0400)
commitfb2cca828ec84f58bf119b65a4d6051400fe9438
treedb21505e3a7b6f811deb34791c315f3dcbbb1cd5
parent5656f2c3dce529b688eeeb2e98357c961376af80
Fix old bug with coercing the result of a COLLATE expression.

There are hacks in parse_coerce.c to push down a requested coercion
to below any CollateExpr that may appear.  However, we did that even
if the requested data type is non-collatable, leading to an invalid
expression tree in which CollateExpr is applied to a non-collatable
type.  The fix is just to drop the CollateExpr altogether, reasoning
that it's useless.

This bug is ten years old, dating to the original addition of
COLLATE support.  The lack of field complaints suggests that there
aren't a lot of user-visible consequences.  We noticed the problem
because it would trigger an assertion in DefineVirtualRelation if
the invalid structure appears as an output column of a view; however,
in a non-assert build, you don't see a crash just a (subtly incorrect)
complaint about applying collation to a non-collatable type.  I found
that by putting the incorrect structure further down in a view, I could
make a view definition that would fail dump/reload, per the added
regression test case.  But CollateExpr doesn't do anything at run-time,
so this likely doesn't lead to any really exciting consequences.

Per report from Yulin Pei.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/HK0PR01MB22744393C474D503E16C8509F4709@HK0PR01MB2274.apcprd01.prod.exchangelabs.com
src/backend/parser/parse_coerce.c
src/test/regress/expected/collate.out
src/test/regress/sql/collate.sql