Re: Let join syntax

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Let join syntax
Дата
Msg-id 2736.1055773873@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Let join syntax  (Manfred Koizar <mkoi-pg@aon.at>)
Список pgsql-sql
Manfred Koizar <mkoi-pg@aon.at> writes:
> On Mon, 16 Jun 2003 12:34:34 +0200, "Nicolas JOUANIN"
> <n.jouanin@regie-france.com> wrote:
>> from
>> coh x0 , cpy x1 ,bra x2 ,
>> cur x3  ,tad x4 LEFT OUTER JOIN sec x5 on x5.thr_id=x4.thr_id AND
>> x5.usr_id=x0.usr_id AND [...]
>> 
>> Unfortunatelly, postgres returns me the following error :
>> Error: ERROR:  Relation "x0" does not exist

> Yes, because the LEFT OUTER JOIN only sees x4 and x5.

The way that query is constructed, you've put all of the join conditions
into the LEFT JOIN's constraint, which will not do what you want even if
there weren't a syntactic failure.  As an example, consider the
difference between
(a cross join b) left join c on (a.a1 = b.b1 and a.a2 = c.c2)
(a join b on a.a1 = b.b1) left join c on (a.a2 = c.c2)

The former is almost surely wrong: it will produce a row for *every*
combination in the cross product of a and b.  Rows where a1 != b1 will
still be emitted --- but the c columns will be nulled out, even if
a2 = c2 is true, because the left join condition is false at such rows.
The second one is probably what was meant, instead.

In short, the reason why the SQL spec syntax for JOIN is the way it is
is that there's a big difference between conditions you put in an outer
join's ON clause and those you put elsewhere.
        regards, tom lane


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

Предыдущее
От: Tomasz Myrta
Дата:
Сообщение: casting interval to time
Следующее
От: Manfred Koizar
Дата:
Сообщение: Re: Let join syntax