Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Aggregate Functions

Aggregate functions compute aggregated results from zero or more input values and have the form

<name> ( [ all | distinct ] <expr> ) [ where <pred> ]

where

  • <name> is an identifier naming the function,
  • all and distinct are optional keywords,
  • <expr> is any expression that is type compatible with the particular function, and
  • <pred> is an optional Boolean expression that filters inputs to the function.

Aggregate functions may appear in

When aggregate functions appear in context of grouping (e.g., the by clause of an aggregate operator or a SQL operator with a GROUP BY clause), then the aggregate function produces one output value for each unique combination of grouping expressions.

If the case-insensitive distinct option is present, then the inputs to the aggregate function are filtered to unique values for each unique grouping.

If the case-insensitive all option is present, then all values for each unique group are passed as input to the aggregate function.

Calling an aggregate function in a pipe-operator expression outside of an aggregating context is an error.