Re: pg_get_viewdef() produces non-round-trippable SQL for views with USING join on mismatched integer types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Swirl Smog Dowry <swirl-smog-dowry(at)duck(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: pg_get_viewdef() produces non-round-trippable SQL for views with USING join on mismatched integer types
Date: 2026-02-26 18:27:10
Message-ID: 717830.1772130430@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Attachment Content-Type Size
wip-preserve-join-aliases-in-RTE_GROUP.patch text/x-diff 2.1 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2026-02-26 23:18:09 Re: basic_archive lost archive_directory
Previous Message Tom Lane 2026-02-26 16:18:14 Re: BUG #19417: '\dD' fails to list user-defined domains that shadow built-in type names (e.g., 'numeric')