Re: How to do this in PostgreSQL?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Robert Nosko" <robertn(at)eori(dot)net(dot)pl>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to do this in PostgreSQL?
Date: 2000-04-10 19:50:27
Message-ID: 17328.955396227@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Robert Nosko" <robertn(at)eori(dot)net(dot)pl> writes:
> In ORACLE I can perform the following query:

> SELECT tableA.id, title, qty
> FROM tableA, (SELECT id, count(*) qty FROM tableB group by id) tableC
> WHERE tableA.id = tableC.id (+)

> but in PostgreSQL I get error message.

We don't currently have sub-SELECTs in FROM (maybe in 7.1 though).
I doubt we ever will support that nonstandard "(+)" syntax (that's
Oracle-speak for an outer join, no?).

But 7.0 does handle sub-SELECTs in the result list, so you could do

SELECT id, title,
(SELECT count(*) FROM tableB where tableB.id = tableA.id) AS qty
FROM tableA;

This will be slower than the other way, probably, but it works and is
at least as readable.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mitch Vincent 2000-04-10 20:36:03 Speedy query help..
Previous Message mig 2000-04-10 18:45:13 [mig@utdt.edu: Re: Threaded Records in SQL: Advice Needed]