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