Re: BUG #2549: problem with NATURAL JOIN

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Kayteck <kayteck_master(at)o2(dot)pl>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2549: problem with NATURAL JOIN
Date: 2006-07-25 12:02:39
Message-ID: 20060725120239.GA35144@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Jul 25, 2006 at 12:58:55AM +0000, Kayteck wrote:
> I have two tables joined by foreign key id_przelewu, and for some rows
> results of queries with NATURAL JOIN and JOIN ... USING (...) differs ! I've
> readed that NATURAL JOIN is only shorthand for the second method, but this
> results shows that's not true:
[...]
> select id_przelewu,id_zamowienia from zamowienia natural join przelew where
> id_klienta=4999;
> id_przelewu | id_zamowienia
> -------------+---------------
> (0 rows)

Do zamowienia and przelew have column names in common in addition
to id_przelewu? NATURAL JOIN uses all common column names, not
just those specified in a foreign key constraint.

http://www.postgresql.org/docs/8.1/interactive/queries-table-expressions.html#QUERIES-FROM

"Finally, NATURAL is a shorthand form of USING: it forms a USING
list consisting of exactly those column names that appear in both
input tables."

http://www.postgresql.org/docs/8.1/interactive/sql-select.html#SQL-FROM

"NATURAL is shorthand for a USING list that mentions all columns
in the two tables that have the same names."

--
Michael Fuhr

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Simon Riggs 2006-07-25 12:08:14 Re: BUG #2549: problem with NATURAL JOIN
Previous Message Bruce Momjian 2006-07-25 02:50:27 Re: BUG #2546: PostgreSQL does not have native spinlock