Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR

Поиск
Список
Период
Сортировка
От Magnus Hagander
Тема Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR
Дата
Msg-id CABUevEz6rfHg2w1AWFM8HHK0zpuy_Q-BzudPRO8O=H2CL0k-Aw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
On Sun, Jan 31, 2021 at 1:01 AM Carlos Sotto Maior (UOL)
<csotto@uol.com.br> wrote:
>
> Thanks a lot Tom.
> I'll solve it with a subquery.

No need for a subquery. In your particular case,  it should just work with:

SELECT count(*) as cnt, f1, f2, active
                FROM public.z_having
                GROUP BY f1, f2, active
                HAVING active = True AND count(*) > 1
                ORDER BY cnt DESC


It can get ugly if your aggregates are large and complex, but not for
a simple count(*)...

//Magnus



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

Предыдущее
От: PG Bug reporting form
Дата:
Сообщение: BUG #16846: "retrieved too many tuples in a bounded sort"
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #16846: "retrieved too many tuples in a bounded sort"