Thread: pgsql: Allow ORDER BY/GROUP BY/etc items to match targetlist items

pgsql: Allow ORDER BY/GROUP BY/etc items to match targetlist items

From
tgl@postgresql.org (Tom Lane)
Date:
Log Message:
-----------
Allow ORDER BY/GROUP BY/etc items to match targetlist items regardless of
any implicit casting previously applied to the targetlist item.  This is
reasonable because the implicit cast, by definition, wasn't written by the
user; so we are preserving the expected behavior that ORDER BY items match
textually equivalent tlist items.  The case never arose before because there
couldn't be any implicit casting of a top-level SELECT item before we process
ORDER BY etc.  But now it can arise in the context of aggregates containing
ORDER BY clauses, since the "targetlist" is the already-casted list of
arguments for the aggregate.  The net effect is that the datatype used for
ORDER BY/DISTINCT purposes is the aggregate's declared input type, not that
of the original input column; which is a bit debatable but not horrendous,
and to do otherwise would require major rework that doesn't seem justified.

Per bug #5564 from Daniel Grace.  Back-patch to 9.0 where aggregate ORDER BY
was implemented.

Tags:
----
REL9_0_STABLE

Modified Files:
--------------
    pgsql/src/backend/parser:
        parse_clause.c (r1.198 -> r1.198.4.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_clause.c?r1=1.198&r2=1.198.4.1)
    pgsql/src/test/regress/expected:
        aggregates.out (r1.21 -> r1.21.6.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/aggregates.out?r1=1.21&r2=1.21.6.1)
    pgsql/src/test/regress/sql:
        aggregates.sql (r1.17 -> r1.17.6.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/aggregates.sql?r1=1.17&r2=1.17.6.1)