Skip site navigation (1) Skip section navigation (2)

Re: Syntax question: use of join/using with fully qualified table name

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bryce Nesbitt <bryce1(at)obviously(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Syntax question: use of join/using with fully qualified table name
Date: 2008-01-28 01:45:17
Message-ID: 16133.1201484717@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
Bryce Nesbitt <bryce1(at)obviously(dot)com> writes:
> I've got a join where a certain column name appears twice:
> select username,last_name from eg_member join eg_membership using
> (member_id) join eg_account using (account_id) join eg_person using
> (person_id);
> ERROR:  common column name "person_id" appears more than once in left table

> My first inclination was to fully quality the table name.  Why would
> this not be acceptable syntax?

Because USING is defined as joining common column names.  It is driven
entirely by the column names, not any "qualification", and it needs to
have well-defined behavior.  The SQL92 spec saith

         <named columns join> ::=
              USING <left paren> <join column list> <right paren>

         <join column list> ::= <column name list>

         <column name list> ::=
              <column name> [ { <comma> <column name> }... ]

         <column name> ::= <identifier>

         ...

            b) If a <named columns join> is specified, then every <column
              name> in the <join column list> shall be the <column name>
              of exactly one column of T1 and the <column name> of exactly
              one column of T2.

			regards, tom lane

In response to

pgsql-sql by date

Next:From: Bryce NesbittDate: 2008-01-28 02:30:59
Subject: extract or date_part on an interval? How many e
Previous:From: Martin MarquesDate: 2008-01-28 01:43:04
Subject: Re: Syntax question: use of join/using with fully qualified table name

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group