Multiple natural joins

From: Thom Brown <thombrown(at)gmail(dot)com>
To: PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Multiple natural joins
Date: 2009-03-19 11:24:34
Message-ID: bddc86150903190424m709a6ddalebe7106132f055aa@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joachim Tranvåg 2009-03-19 11:38:13 Re: (0x0000274D/10061) on Install
Previous Message Milos Findura 2009-03-19 09:13:43 deadlock problem