Re: [GENERAL] Fields re-ordered on JOIN with * and USING - Mailing list pgsql-general

From Tom Lane
Subject Re: [GENERAL] Fields re-ordered on JOIN with * and USING
Date
Msg-id 5617.1504314270@sss.pgh.pa.us
Whole thread Raw
In response to Re: [GENERAL] Fields re-ordered on JOIN with * and USING  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Sep 1, 2017 at 2:25 PM, Ken Tanzer <ken.tanzer@gmail.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


pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: [GENERAL] Fields re-ordered on JOIN with * and USING
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] Fields re-ordered on JOIN with * and USING