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

From Tom Lane
Subject Re: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR
Date
Msg-id 3011179.1612046789@sss.pgh.pa.us
Whole thread Raw
In response to Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR  ("Carlos Sotto Maior \(UOL\)" <csotto@uol.com.br>)
List pgsql-bugs
"Carlos Sotto Maior \(UOL\)" <csotto@uol.com.br> writes:
> In other words: Postgresql is matching <HAVING> arguments to columns at
> table level instead of matching to a group by result level.

That's per SQL standard.  The fact that we allow the case in
GROUP BY is an anachronism.  (You'll find also that we only allow it
for GROUP BY items that are *just* an output column name, not any
more-complicated expression.  The equivalent restriction for HAVING
would make such a feature near useless anyway.)

            regards, tom lane



pgsql-bugs by date:

Previous
From: "Carlos Sotto Maior \(UOL\)"
Date:
Subject: Use of HAVING (Select/Group By) on a output-name of an aggregate function causes SYNTAX ERROR
Next
From: PG Bug reporting form
Date:
Subject: BUG #16846: "retrieved too many tuples in a bounded sort"