Re: Targetlist lost when CTE join <targetlist lost when CTE join>

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Julien Rouhaud <rjuju123(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Targetlist lost when CTE join <targetlist lost when CTE join>
Date: 2023-06-28 09:32:37
Message-ID: cdda6aba-9468-4d4e-90a6-b8f110e2d353@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

HI,

On Jun 28, 2023, 17:26 +0800, Julien Rouhaud <rjuju123(at)gmail(dot)com>, wrote:
> On Wed, Jun 28, 2023 at 05:17:14PM +0800, Julien Rouhaud wrote:
> > >
> > > Table t1 and  t2 both has 2 columns: c1, c2, when CTE join select *, the result target list seems to lost one’s column c1.
> > > But it looks good when select cte1.* and t1.* explicitly .
> > >
> > > Is it a bug?
> >
> > This is working as intended. When using a USING clause you "merge" both
> > columns so the final target list only contain one version of the merged
> > columns, which doesn't happen if you use e.g. ON instead. I'm assuming that
> > what the SQL standard says, but I don't have a copy to confirm.
>
> I forgot to mention that this is actually documented:
>
> https://www.postgresql.org/docs/current/queries-table-expressions.html
>
> Furthermore, the output of JOIN USING suppresses redundant columns: there is no
> need to print both of the matched columns, since they must have equal values.
> While JOIN ON produces all columns from T1 followed by all columns from T2,
> JOIN USING produces one output column for each of the listed column pairs (in
> the listed order), followed by any remaining columns from T1, followed by any
> remaining columns from T2.

Thanks for your help.

Regards,
Zhang Mingli

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2023-06-28 09:37:39 Re: Changing types of block and chunk sizes in memory contexts
Previous Message Julien Rouhaud 2023-06-28 09:26:10 Re: Targetlist lost when CTE join <targetlist lost when CTE join>