Expand description
HAVING planning: bind the predicate to computed aggregate columns.
A HAVING predicate is evaluated against finalized group rows, so every aggregate it mentions must (a) actually be computed and (b) be addressed by the column name it lands under.
Left untranslated, HAVING SUM(amount) > 0 reaches the executor as a
literal sum(...) call over a group row that has no such column and no
scalar sum to apply — every group fails the predicate and the query
returns nothing, for data that plainly satisfies it. And an aggregate named
only in HAVING was never added to the aggregate list, so it was never
computed at all.
HAVING filters before aggregates are renamed to their user aliases, so it binds to the canonical key.
Functions§
- plan_
having - Convert a HAVING clause into filters over finalized group rows.