Re: Statement parsing problem ?

From: James Robinson <jlrobins(at)socialserve(dot)com>
To: Chris Dunlop <chris(at)onthe(dot)net(dot)au>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Statement parsing problem ?
Date: 2004-09-15 13:59:28
Message-ID: 75CB5A78-071F-11D9-A5EE-000A9566A412@socialserve.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On Sep 15, 2004, at 9:43 AM, Chris Dunlop wrote:

> Either that, or I'm missing something...

From the SELECT docs ...

A JOIN clause combines two FROM items. Use parentheses if necessary
to determine the order of nesting. In the absence of parentheses,
JOINs nest left-to-right. In any case JOIN binds more tightly than the
commas separating FROM items.

CROSS JOIN and INNER JOIN produce a simple Cartesian product, the
same result as you get from listing the two items at the top level of
FROM, but restricted by the join condition (if any). CROSS JOIN is
equivalent to INNER JOIN ON (TRUE), that is, no rows are removed by
qualification. These join types are just a notational convenience,
since they do nothing you couldn't do with plain FROM and WHERE.
---

Since you're doing a simple join, you'd be better off using form

select 1 as "OK" from t1, t2, t3, t4 on where t4.foo6 = t3.foo5 and
t2.foo3 = t1.foo1 and t3.foo4 = t1.foo2 ;

and then you can vary the order of the and clauses any way you like.

But using the "FROM t1, t2, t3 JOIN t4" form binds left-to-right tigher
than the comma separated list, so it is operating on exactly two tables
(t3 and t4), not the t1, t2, t3 cartesian product joined with t4.

----
James Robinson
Socialserve.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2004-09-15 14:06:26 PL/PgSQL "bare" function calls
Previous Message Tom Lane 2004-09-15 13:57:41 Re: Rollback on Error