Re: Left join syntax error

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Left join syntax error
Дата
Msg-id 2762582.1716045418@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Left join syntax error  (Erik Wienhold <ewie@ewie.name>)
Список pgsql-general
Erik Wienhold <ewie@ewie.name> writes:
> But I wonder if the implicit cross join syntax ("FROM peoples, companies")
> should actually produce this error because the explicit cross join
> works:

>     SELECT p.lname, p.fname, p.job_title, p.company_nbr, p.email, c.company_name
>     FROM people as p
>         CROSS JOIN companies as c
>         LEFT JOIN companies ON c.company_nbr = p.company_nbr;

> But I'm not even sure if implicit and explicit cross join are
> semantically equivalent.

Well, they do the same thing, but JOIN binds tighter than comma.
So in one case you have effectively

    FROM people as p CROSS JOIN
         (companies as c LEFT JOIN companies ON c.company_nbr = p.company_nbr)

and "p" is not within the scope of the JOIN/ON clause.
The other way is effectively

    FROM (people as p CROSS JOIN companies as c)
         LEFT JOIN companies ON c.company_nbr = p.company_nbr;

which is syntactically legal, although it probably doesn't do
what you wanted.

If memory serves, MySQL got this basic syntactic detail wrong
for years, as a result of which there's (still) a tremendous amount
of confusion on the net about what is the syntactic precedence in
FROM clauses.

            regards, tom lane



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

Предыдущее
От: Erik Wienhold
Дата:
Сообщение: Re: Left join syntax error
Следующее
От: Rich Shepard
Дата:
Сообщение: Re: Left join syntax error