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


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Reply via email to