From: Tom Lane <tgl@sss.pgh.pa.us>
To: Manfred Koizar <mkoi-pg@aon.at>
Cc: Nicolas JOUANIN <n.jouanin@regie-france.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Let join syntax
Date: Mon, 16 Jun 2003 10:31:13 -0400
Message-ID: <2736.1055773873@sss.pgh.pa.us> (raw)
In-Reply-To: <838rev0q8nt2j1pltfpq30akoqbc3rdcs7@4ax.com>
References: <CEEJJOCKHCPFNIOMMIDFGECICHAA.n.jouanin@regie-france.com>
<838rev0q8nt2j1pltfpq30akoqbc3rdcs7@4ax.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, mkoi-pg@aon.at, n.jouanin@regie-france.com
Subject: Re: Let join syntax
In-Reply-To: <2736.1055773873@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox