Re: WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation
Дата
Msg-id 17509.1230336828@sss.pgh.pa.us
обсуждение исходный текст
Ответ на WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Ответы Re: WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation  (David Fetter <david@fetter.org>)
subselect and count (DISTINCT expression [ , ... ] ) performances  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Список pgsql-general
Ivan Sergio Borgonovo <mail@webthatworks.it> writes:
>>> David Fetter <david@fetter.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

В списке pgsql-general по дате отправления:

Предыдущее
От: Ivan Sergio Borgonovo
Дата:
Сообщение: WITH AS vs subselect was: count (DISTINCT expression [ , ... ] ) and documentation
Следующее
От: "Eric Worden"
Дата:
Сообщение: "disappearing" rows in temp table, in recursing trigger