Re: Complex outer joins? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Complex outer joins?
Date
Msg-id 7039.1048718031@sss.pgh.pa.us
Whole thread Raw
In response to Re: Complex outer joins?  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Responses Re: Complex outer joins?  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-sql
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> On 26 Mar 2003, Greg Stark wrote:
>> Can you show an example where the join order would affect the result set? I
>> can't think of any.

> I can think of a few somewhat degenerate cases.

I don't think you need a degenerate case.  Consider
   from (G left join L on (G.SELID = L.SELID))        right join C on (L.SELID = C.SELID)

versus
    from G left join         (L right join C on (L.SELID = C.SELID))         on (G.SELID = L.SELID)

In the former case you will see rows out for every SELID existing in C;
in the latter case, rows out for every SELID existing in G, which may
include rows having no match in C.  The set of joined rows is the same
in either case, but the set of rows added for unjoined keys differs.

The difference between this and the query we were discussing is just use
of "right" rather than "left" in the second JOIN.  AIUI, in the Oracle
syntax this difference would be expressed by moving the (*) from one
side to the other of the L.SELID = C.SELID clause.  Unless they have
strange restrictions on the combinations of clauses you can mark with
(*), I don't see how they can assume that join order is insignificant.
        regards, tom lane



pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: How can I pass an array from PostgreSQL to C (libpq)?
Next
From: Stephan Szabo
Date:
Subject: Re: Complex outer joins?