Re: Multiple natural joins

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Multiple natural joins
Дата
Msg-id 49C25540.9020606@gmx.net
обсуждение исходный текст
Ответ на Multiple natural joins  (Thom Brown <thombrown@gmail.com>)
Ответы Re: Multiple natural joins  (Sam Mason <sam@samason.me.uk>)
Список pgsql-general
Thom Brown wrote:
> 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?

The fact that the above example runs proves that natural joins are
allowed with more than 2 tables.

Joins nest from left to write, so

tbl_c NATURAL JOIN tbl_a NATURAL JOIN tbl_b

means

(tbl_c NATURAL JOIN tbl_a) NATURAL JOIN tbl_b

and that means that the second join is executed as if the first join
resulted in a normal table with normal columns with names as the case
may be, and the natural join will use those names with all the consequences.

If you want a different order, you can set the parentheses differently,
with possibly different results.

The fact that this isn't entirely obvious only supports the argument
that natural joins shouldn't used.


В списке pgsql-general по дате отправления:

Предыдущее
От: Milos Findura
Дата:
Сообщение: Re: deadlock problem
Следующее
От: "Rob Richardson"
Дата:
Сообщение: Changing pg_type records