Re: BUG #2549: problem with NATURAL JOIN - Mailing list pgsql-bugs

From Simon Riggs
Subject Re: BUG #2549: problem with NATURAL JOIN
Date
Msg-id 1153829294.2592.545.camel@holly
Whole thread Raw
In response to BUG #2549: problem with NATURAL JOIN  ("Kayteck" <kayteck_master@o2.pl>)
List pgsql-bugs
On Tue, 2006-07-25 at 00:58 +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:

NATURAL JOIN is shorthand for a USING () clause that mention *all*
columns with matching names, so the meaning is slightly different.

> select id_przelewu,id_zamowienia from zamowienia natural join przelew where
> id_klienta=4999;
>  id_przelewu | id_zamowienia
> -------------+---------------
> (0 rows)
>
> select id_przelewu,id_zamowienia from zamowienia join przelew using (id_p
> rzelewu) where id_klienta=4999;
>  id_przelewu | id_zamowienia
> -------------+---------------
>         3095 |          7504
>         3095 |          7503
>         3095 |          7408
> (3 rows)

We cannot see whether this is a bug or not, since you have not provided
the full descriptions of the two tables involved. Without those we
cannot tell whether the NATURAL JOIN isn't shorthand for this...

select id_przelewu,id_zamowienia from zamowienia join przelew using
(id_przelewu, matching_name_col1, ...) where id_klienta=4999;

and could therefore provide a different answer.

--
  Simon Riggs
  EnterpriseDB   http://www.enterprisedb.com

pgsql-bugs by date:

Previous
From: John Weekley
Date:
Subject: Re: BUG #2546: PostgreSQL does not have native spinlock
Next
From: Tom Lane
Date:
Subject: Re: BUG #2549: problem with NATURAL JOIN