Support-function states

The database server uses the following steps to find the support functions:
  1. If the CREATE AGGREGATE statement includes an INIT function, resolve the following UDR:
    init_func (dt_agg, dt_setup)

    The return type of the INIT function establishes a state type that the database server uses to resolve the other support functions. If the INIT function is omitted, the state type is the data type of the argument of the aggregate.

  2. For the ITER function, resolve the following UDR:
    iter_func (state_type, dt_agg)

    The return type of the ITER function should be the state type.

  3. For the COMBINE function, resolve the following UDR:
    comb_func (state_type, state_type)

    The return type of the COMBINE function should be the state type.

  4. If the FINAL function is specified, resolve the following UDR:
    final_func (state_type)

    The return type of the user-defined aggregate is the return type of the FINAL function. If the FINAL function is not specified, the return type is the state type.

The preceding steps use the following variables.

comb_func
Name of the COMBINE function
dt_aggr
Data type of the first argument of the aggregate
dt_setup
Data type of the second, or setup, argument of the aggregate
final_func
Name of the FINAL function
init_func
Name of the INIT function
iter_func
Name of the ITER function
state_type
The state type that the return value of the INIT function establishes

Aggregate states should never be null. That is, the support functions should not return a null value. The database server cannot distinguish a null value from the result of aggregating over an empty table. Therefore, although null values do not cause runtime errors, the COMBINE function and the FINAL function ignore them.