From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation |
Date: | 2008-12-27 00:13:48 |
Message-ID: | 17509.1230336828@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> writes:
>>> David Fetter <david(at)fetter(dot)org> wrote:
>>>> In 8.4, you'll be able to do:
>>>> WITH d AS (
>>>> SELECT DISTINCT c1, c2 FROM table1
>>>> )
>>>> SELECT count(*) FROM d;
>>> Nice, but what will be the difference from
>>> select count(*) from (select distinct c1, c2 from t);
>>> ?
>>> Optimisation?
>> None especially.
> So what would be the advantage compared to subselect?
None, David just has WITH on the brain ;-)
The subselect syntax certainly seems like the one most likely to work
across different SQL implementations. WITH is a pretty recent addition
to the SQL spec, and DISTINCT with multiple aggregate arguments isn't
in the spec at all. The COUNT(DISTINCT ROW(x,y)) hack is a cute idea
but I'm dubious that that's portable either (it certainly doesn't work
in pre-8.4 PG).
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Eric Worden | 2008-12-27 03:15:44 | "disappearing" rows in temp table, in recursing trigger |
Previous Message | Ivan Sergio Borgonovo | 2008-12-26 22:17:06 | WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation |