X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 797C030EDD5 for ; Mon, 16 Jun 2003 14:31:36 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 34845-02 for ; Mon, 16 Jun 2003 11:31:23 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id A402D30ED14 for ; Mon, 16 Jun 2003 11:31:22 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5GEVDU6002737; Mon, 16 Jun 2003 10:31:14 -0400 (EDT) To: Manfred Koizar Cc: "Nicolas JOUANIN" , pgsql-sql@postgresql.org Subject: Re: Let join syntax In-reply-to: <838rev0q8nt2j1pltfpq30akoqbc3rdcs7@4ax.com> References: <838rev0q8nt2j1pltfpq30akoqbc3rdcs7@4ax.com> Comments: In-reply-to Manfred Koizar message dated "Mon, 16 Jun 2003 12:57:37 +0200" Date: Mon, 16 Jun 2003 10:31:13 -0400 Message-ID: <2736.1055773873@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/141 X-Sequence-Number: 13899 Manfred Koizar writes: > On Mon, 16 Jun 2003 12:34:34 +0200, "Nicolas JOUANIN" > 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