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-27 18:08:36
Message-ID: 988126.1772215716@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> Richard Guo <guofenglinux(at)gmail(dot)com> writes:
>> I am on the fence about whether this fix is safe to back-patch to v18.

> I don't think we have a lot of choice. The cases where it makes a
> difference are pretty broken. Fortunately, I think these cases
> are rare. JOIN USING combining two different-type columns has got
> to be an edge-case usage, and I think it likely doesn't matter much
> in other cases.

I spent a bit of effort on determining which cases actually cause
wrong output, and AFAICT it's very narrow: you need "SELECT ...
t1 LEFT JOIN t2 USING (x) GROUP BY x" where t1.x and t2.x are
different data types and t1.x is the side requiring coercion.
With no coercion, or if the join side to be coerced is nullable, we
show the flattened alias Var but that doesn't actually break anything.

So I went ahead and pushed this, using your test case.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-02-27 21:22:25 Re: Major Version Upgrade failure due to orphan roles entries in catalog
Previous Message Tom Lane 2026-02-27 15:21:43 Re: pg_get_viewdef() produces non-round-trippable SQL for views with USING join on mismatched integer types