Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics
Дата
Msg-id 30939.1526913927@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics  (Alexey Dokuchaev <danfe@nsu.ru>)
Список pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
>> Is it possible to obtain the
>> first ROW_COUNT (after SELECT) without performing it twice?

> ​Not directly, no.  You should execute the inner query to a temporary table
> than perform your counting and json_agg from that.

OP could do something like

        declare r record;
        ...
        select json_agg(_) as j, count(*) as c INTO r FROM (
          SELECT foo, bar, baz ...
          FROM t1, t2, t3 WHERE ...) AS _;

This would be slightly more expensive than doing only the one aggregate,
but it should beat anything involving a temp table.

            regards, tom lane


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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics
Следующее
От: Yashwanth Govinda Setty
Дата:
Сообщение: Will Altering and Modifying tables during backup result in acorrupted server after the restore?