From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: rekgrpth@gmail.com <rekgrpth@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #18307: system columns does not support using join
Date: Wed, 24 Jan 2024 22:54:10 -0500
Message-ID: <264096.1706154850@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbpw_WhcB=w_MwUWjMGVYH=Hxr3bW0vOpbLH8QFMsgqxg@mail.gmail.com>
References: <18307-16a12cbeb212d742@postgresql.org>
<CAKFQuwbpw_WhcB=w_MwUWjMGVYH=Hxr3bW0vOpbLH8QFMsgqxg@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tuesday, January 23, 2024, PG Bug reporting form <noreply@postgresql.org>
> wrote:
>> create table t(i int);
>>
>> explain (costs off) select * from t join t tt on t.xmin = tt.xmin;
>> QUERY PLAN
>> ---------------------------------
>> Hash Join
>> Hash Cond: (t.xmin = tt.xmin)
>> -> Seq Scan on t
>> -> Hash
>> -> Seq Scan on t tt
>> (5 rows)
>>
>> explain (costs off) select * from t join t tt using (xmin);
>> ERROR: column "xmin" specified in USING clause does not exist in left
>> table
> I don’t this being worth the effort to change, and really seems like
> completely expected behavior. “Select *” doesn’t output xmin, it requires
> explicit table qualification to see it. This is the same thing.
Well, it is odd that "using (xmin)" isn't equivalent to the allegedly
equivalent "on t.xmin = tt.xmin". This is down to the infrastructure
in transformFromClauseItem(), which searches the lists of (regular,
non-system) relation output column names to expand USING(). But like
you, I can't get excited about changing it. There are a couple of
practical reasons why not:
* NATURAL JOIN is defined in terms of USING. But we *certainly* don't
want "x NATURAL JOIN y" deciding that it should equate all the system
columns of x to those of y. So there's going to be inconsistency at
one level or the other no matter what.
* I really find it hard to imagine a valid use case for joining on any
system column. There are use-cases for joining on TID in an UPDATE
involving a self-join to the target table; but you can't write that
with JOIN USING syntax.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, rekgrpth@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18307: system columns does not support using join
In-Reply-To: <264096.1706154850@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox