Skip to main content

Module agg_bind

Module agg_bind 

Source
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 said SUM(amount) AS total).

Enums§

BindName
Which name an aggregate call is rewritten to.

Functions§

bind_aggregate_calls
Rewrite every aggregate call in expr to a reference to its computed column, registering aggregates the projection did not already request.