From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Manfred Koizar <mkoi-pg(at)aon(dot)at> |
Cc: | "Nicolas JOUANIN" <n(dot)jouanin(at)regie-france(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Let join syntax |
Date: | 2003-06-16 14:31:13 |
Message-ID: | 2736.1055773873@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Manfred Koizar <mkoi-pg(at)aon(dot)at> writes:
> On Mon, 16 Jun 2003 12:34:34 +0200, "Nicolas JOUANIN"
> <n(dot)jouanin(at)regie-france(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Manfred Koizar | 2003-06-16 14:39:32 | Re: Let join syntax |
Previous Message | Tomasz Myrta | 2003-06-16 13:51:35 | casting interval to time |