Re: Statement parsing problem ? - Mailing list pgsql-hackers

From James Robinson
Subject Re: Statement parsing problem ?
Date
Msg-id 75CB5A78-071F-11D9-A5EE-000A9566A412@socialserve.com
Whole thread Raw
In response to Statement parsing problem ?  (Chris Dunlop <chris@onthe.net.au>)
List 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



pgsql-hackers by date:

Previous
From: Chris Dunlop
Date:
Subject: Statement parsing problem ?
Next
From: Tom Lane
Date:
Subject: Re: libpq and prepared statements progress for 8.0