The RTE's groupexprs list is used for deparsing views, and for that usage it must contain the original alias Vars; else we can get incorrect SQL output. But since commit 247dea89f, parseCheckAggregates put the GROUP BY expressions through flatten_join_alias_vars before building the RTE_GROUP RTE. Changing the order of operations there is enough to fix it. This patch unfortunately can do nothing for already-created views: if they use a coding pattern that is subject to the bug, they will deparse incorrectly and hence present a dump/reload hazard in the future. The only fix is to recreate the view from the original SQL. But the trouble cases seem to be quite narrow. AFAICT the output was only wrong for "SELECT ... t1 LEFT JOIN t2 USING (x) GROUP BY x" where t1.x and t2.x were not of identical data types and t1.x was the side that required an implicit coercion. If there was no hidden coercion, or if the join was plain, RIGHT, or FULL, the deparsed output was uglier than intended but not functionally wrong. Reported-by: Swirl Smog Dowry <swirl-smog-dowry@duck.com> Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Discussion: https://postgr.es/m/CA+-gibjCg_vjcq3hWTM0sLs3_TUZ6Q9rkv8+pe2yJrdh4o4uoQ@mail.gmail.com Backpatch-through: 18
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/18/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/18/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.