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

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

  1. Don't flatten join alias Vars that are stored within a GROUP RTE.

  2. Introduce an RTE for the grouping step