pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tambet Matiisen <t.matiisen@aprote.ee>
To: Marko Asplund <aspa@kronodoc.fi>
To: pgsql-sql@postgresql.org
Subject: Re: Oracle outer join porting question
Date: Wed, 15 Jan 2003 16:40:32 +0200
Message-ID: <81132473206F3A46A72BD6116E1A06AE3EC030@black.aprote.com> (raw)



> -----Original Message-----
> From: Marko Asplund [mailto:aspa@kronodoc.fi]
> Sent: Wednesday, January 15, 2003 4:31 PM
> To: pgsql-sql@postgresql.org
> Subject: [SQL] Oracle outer join porting question
> 
> 
> 
> i'm trying to port an existing application from Oracle8i to 
> PostgreSQL but
> i'm having problems understanding a certain outer join query 
> type used in
> the application. the query includes a normal outer join 
> between two tables
> but also uses outer join syntax to join a table with a 
> constant. here's a
> simplified version of the query:
> 
> SELECT doc.id,doc.title,sub.user_id,sub.operation
>   FROM document doc, document_subscription sub
>   WHERE 6 = sub.user_id(+) AND sub.document_id(+) = doc.id;
> 
> what does the '6 = sub.user_id(+)' condition exactly do in 
> this query?  
> how would this be translated SQL92 join syntax used by PostgreSQL?
> 
> i've tried converting it to:
> 
> SELECT doc.id,doc.title,sub.user_id,sub.operation
>   FROM document doc LEFT OUTER JOIN document_subscription sub
>   ON sub.document_id = doc.id
>   WHERE (sub.user_id = 6 OR sub.user_id IS NULL);
> 
> but this query is missing the rows in the documents table which have a
> corresponding document_subscription row with 'not user_id = 6'.
> 

Try this:

SELECT doc.id,doc.title,sub.user_id,sub.operation
  FROM document doc LEFT OUTER JOIN document_subscription sub
  ON sub.document_id = doc.id AND sub.user_id = 6; 

  Tambet



view thread (5+ messages)  latest in thread

Message-ID: <81132473206F3A46A72BD6116E1A06AE3EC030@black.aprote.com>
Permalink:  ../81132473206F3A46A72BD6116E1A06AE3EC030@black.aprote.com/
Also on:    postgresql.org/message-id/81132473206F3A46A72BD6116E1A06AE3EC030@black.aprote.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: t.matiisen@aprote.ee, aspa@kronodoc.fi
  Subject: Re: Oracle outer join porting question
  In-Reply-To: <81132473206F3A46A72BD6116E1A06AE3EC030@black.aprote.com>
  References: <81132473206F3A46A72BD6116E1A06AE3EC030@black.aprote.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox