Multiple natural joins - Mailing list pgsql-general

From Thom Brown
Subject Multiple natural joins
Date
Msg-id bddc86150903190424m709a6ddalebe7106132f055aa@mail.gmail.com
Whole thread Raw
Responses Re: Multiple natural joins  (Scott Marlowe <scott.marlowe@gmail.com>)
Re: Multiple natural joins  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-general
Hi,

I've read the PostgreSQL documentation on natural joins, but it only ever shows it being used once.  Is it possible to use it more than once?

Say if I have the following 3 tables (this is a poor example by the way):

tbl_a
--------
a_id serial NOT NULL
location text

tbl_b
--------
b_id serial NOT NULL
language text

tbl_c
--------
c_id serial NOT NULL
a_id int NOT NULL
b_id int NOT NULL

I could write:

SELECT tbl_a.location, tbl_b.language
FROM tbl_c
INNER JOIN tbl_a ON tbl_c.a_id = tbl_a.a_id
INNER JOIN tbl_b ON tbl_c.b_id = tbl_b.b_id;

But could I also write:

SELECT tbl_a.location, tbl_b.language
FROM tbl_c
NATURAL INNER JOIN tbl_a
NATURAL INNER JOIN tbl_b

The confusion comes when 2 of those tables reference the 3rd table using the same column.

So are natural joins only allowed to join 2 tables?  If not, how can it be used for more than 1 table has links to the other tables?

Thanks

Thom

pgsql-general by date:

Previous
From: Milos Findura
Date:
Subject: deadlock problem
Next
From: Scott Marlowe
Date:
Subject: Re: Multiple natural joins