Re: Complex outer joins?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Correia, Carla" <Carla(dot)Correia(at)logicacmg(dot)com>
Cc: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Complex outer joins?
Date: 2003-03-24 15:18:10
Message-ID: 12785.1048519090@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Correia, Carla" <Carla(dot)Correia(at)logicacmg(dot)com> writes:
> Simplified example:

> select G.SELID, G.TEXT,
> L.ID as SELLEVELID , L.SELLEVEL, L.LEVELJOIN, L.LEVELTEXT,
> C.ID as KRITERIENFELDID, C.SELFLD
> from G, L, C
> where
> and G.SELID = L.SELID (+)
> and L.SELID = C.SELID (+)
> and L.SELLEVEL = C.SELLEVEL (+)

> How can i write this in Postgres?

One of the un-fun things about Oracle's nonstandard syntax is that you
can't easily tell what the join order is supposed to be. (At least I
can't; anyone know how this will get interpreted?)

The SQL-standard way of writing this would presumably be either

from G left join L on (G.SELID = L.SELID)
left join C on (L.SELID = C.SELID and L.SELLEVEL = C.SELLEVEL)

or

from G left join
(L left join C on (L.SELID = C.SELID and L.SELLEVEL = C.SELLEVEL))
on (G.SELID = L.SELID)

depending on which join you think ought to be done first. It might be
that the results are the same in this case, but I'm not convinced of
that. In general the results of outer joins definitely depend on join
order.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Guy Fraser 2003-03-24 15:56:15 Re: What this parser mean?
Previous Message Stephan Szabo 2003-03-24 15:12:35 Re: Complex outer joins?