pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Syntax question: use of join/using with fully qualified table name
3+ messages / 3 participants
[nested] [flat]

* Syntax question: use of join/using with fully qualified table name
@ 2008-01-28 00:49  Bryce Nesbitt <bryce1@obviously.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Bryce Nesbitt @ 2008-01-28 00:49 UTC (permalink / raw)
  To: pgsql-sql

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?

select username,last_name from eg_member join eg_membership using
(member_id) join eg_account using (account_id) join eg_person using
(eg_member.person_id);
ERROR:  syntax error at or near "." at character 145


Of course I eventually wrote it:

select username,last_name from eg_member join eg_membership using (member_id) join eg_account using (account_id) join eg_person on eg_member.person_id=eg_person.person_id';



PostgreSQL 8.1.9 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)


-- 
----
Visit http://www.obviously.com/




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Syntax question: use of join/using with fully qualified table name
@ 2008-01-28 01:43  Martin Marques <martin@marquesminen.com.ar>
  parent: Bryce Nesbitt <bryce1@obviously.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Martin Marques @ 2008-01-28 01:43 UTC (permalink / raw)
  To: Bryce Nesbitt <bryce1@obviously.com>; +Cc: pgsql-sql

Bryce Nesbitt escribió:
> 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?
> 
> select username,last_name from eg_member join eg_membership using
> (member_id) join eg_account using (account_id) join eg_person using
> (eg_member.person_id);
> ERROR:  syntax error at or near "." at character 145

Did you read the manual?

USING (join_column [, ...])

     A clause of the form USING ( a, b, ... ) is shorthand for ON 
left_table.a = right_table.a AND left_table.b = right_table.b .... Also, 
USING implies that only one of each pair of equivalent columns will be 
included in the join output, not both.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Syntax question: use of join/using with fully qualified table name
@ 2008-01-28 01:45  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bryce Nesbitt <bryce1@obviously.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2008-01-28 01:45 UTC (permalink / raw)
  To: Bryce Nesbitt <bryce1@obviously.com>; +Cc: pgsql-sql

Bryce Nesbitt <bryce1@obviously.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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2008-01-28 01:45 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-01-28 00:49 Syntax question: use of join/using with fully qualified table name Bryce Nesbitt <bryce1@obviously.com>
2008-01-28 01:43 ` Martin Marques <martin@marquesminen.com.ar>
2008-01-28 01:45 ` Tom Lane <tgl@sss.pgh.pa.us>

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