Re: pg_get_viewdef() produces non-round-trippable SQL for views with USING join on mismatched integer types
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Swirl Smog Dowry <swirl-smog-dowry@duck.com>,
pgsql-bugs@lists.postgresql.org
Date: 2026-02-26T18:27:10Z
Lists: pgsql-bugs
Attachments
- wip-preserve-join-aliases-in-RTE_GROUP.patch (text/x-diff) patch
I wrote: > The first groupexpr is the same as the joinaliasvars entry for that > column in the JOIN RTE. This surprises me: I'd expect to see a > reference to the join output column there, ie Var 3/1, because I'm > pretty sure that's what parsing of "GROUP BY year" would have produced > initially. If it were like that, I think ruleutils would produce the > desired output. So I'd tentatively classify this as "join alias Vars > are being flattened too soon". Richard, any thoughts? The problem is obvious after looking at parseCheckAggregates: the RTE_GROUP RTE is manufactured using the groupClauses list after we have flattened that, which we are only doing for comparison purposes; it shouldn't affect what goes into the parse tree. I experimented with just changing the order of operations, and that seems to fix it. The lack of any effect on check-world shows we need more test cases here ... regards, tom lane
Commits
-
Don't flatten join alias Vars that are stored within a GROUP RTE.
- c2c1962a64b5 18.4 landed
- 98616ac18b49 19 (unreleased) landed
-
Introduce an RTE for the grouping step
- 247dea89f761 18.0 cited