Re: BUG #2549: problem with NATURAL JOIN

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
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:08:14
Message-ID: 1153829294.2592.545.camel@holly
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2006-07-25 12:22:05 Re: BUG #2549: problem with NATURAL JOIN
Previous Message Michael Fuhr 2006-07-25 12:02:39 Re: BUG #2549: problem with NATURAL JOIN