From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: JSONB_AGG: aggregate function calls cannot be nested |
Date: | 2021-02-20 19:14:03 |
Message-ID: | CAKFQuwawYEq+K3W4ZL=teSfJM8OdLzpsZ8kx-xSNBGAc6+SAWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sat, Feb 20, 2021 at 11:46 AM Alexander Farber <
alexander(dot)farber(at)gmail(dot)com> wrote:
> Then I have to split the query in 3 similar ones (with same condition)?
>
> I try:
>
> SELECT
> JSONB_AGG(TO_CHAR(finished, 'YYYY-MM-DD')) AS day
> FROM words_games
> WHERE finished > CURRENT_TIMESTAMP - INTERVAL '2 week'
> GROUP BY day
> ORDER BY day;
> ERROR: aggregate functions are not allowed in GROUP BY
> LINE 2: JSONB_AGG(TO_CHAR(finished, 'YYYY-MM-DD')) A...
> ^
>
That's a whole different misunderstanding of aggregates that you are seeing.
I mis-spoke in the prior response though. Its not that you only get one
column of an aggregate function per select - you only get to use a single
aggregate in each expression in a select/group-by. array_agg(sum(...)) is
two aggregates in a single expression.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Farber | 2021-02-20 19:33:50 | Re: JSONB_AGG: aggregate function calls cannot be nested |
Previous Message | Alexander Farber | 2021-02-20 18:46:25 | Re: JSONB_AGG: aggregate function calls cannot be nested |