Expand description
Binding aggregate calls in HAVING and post-aggregate ORDER BY.
Both clauses are evaluated against finalized group rows, so an aggregate
either mentions must actually be computed and must be addressed by the
column name it lands under. Left as a literal sum(...) call, it reaches
the executor as a scalar function over a row that has no such column — the
predicate matches nothing, or the sort key resolves to nothing.
The two clauses differ in which name they need, because they run on opposite sides of the rename to user aliases:
- HAVING filters before the rename, so it addresses the canonical key
(
sum(amount)). - ORDER BY sorts after the rename, so it addresses the output name
(
total, when the projection saidSUM(amount) AS total).
Enums§
- Bind
Name - Which name an aggregate call is rewritten to.
Functions§
- bind_
aggregate_ calls - Rewrite every aggregate call in
exprto a reference to its computed column, registering aggregates the projection did not already request.