Re: Fields re-ordered on JOIN with * and USING

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Fields re-ordered on JOIN with * and USING
Date: 2017-09-02 01:04:30
Message-ID: 5617.1504314270@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Fri, Sep 1, 2017 at 2:25 PM, Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> wrote:
>> Hi. I recently noticed that when doing a SELECT * with USING, that the
>> join field(s) appear first in the output. I'd never noticed that before,
>> and was just curious if that is expected behavior or not. Thanks.

> ​I don't recall if or where it is documented but it is intentional., as is
> the documented fact that only one instance of the named column appears in
> the output.

Yes, it's documented, here:

https://www.postgresql.org/docs/current/static/queries-table-expressions.html#QUERIES-FROM

under "7.2.1.1. Joined Tables":

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.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-09-02 01:14:38 Re: Fields re-ordered on JOIN with * and USING
Previous Message David G. Johnston 2017-09-02 00:19:09 Re: Fields re-ordered on JOIN with * and USING