Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics
В списке pgsql-general по дате отправления:
| От | 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
|
| Список | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера