Create Aggregate
Defines a new aggregate function within the database.
Synopsis
CREATE AGGREGATE name ( BASETYPE = input_type [ , SFUNC = sfunc, STYPE = state_type ] [ , FINALFUNC = ffunc ] [ , INITCOND = initial_condition ] )
Parameters
nameThe name of the aggregate function you are creating.
input_typeThe input data type on which the new function will operate. If the aggregate function ignores input values (as the
count()function does), you can use theANYstring constant as the data type.sfuncThe name of the function you wish to be called to handle all non-
NULLinput data values. These functions usually follow the same format, having two arguments. The first argument is of thestate_typedata type, and the second of theinput_typedata type. If the aggregate does not examine input values, it will take only one argument of typestate_type. Either way, the function must return a value of typestate_type.state_typeThe data type for the state value of the aggregate.
ffuncThe name of the final function called upon to compute the aggregate’s result after all input has been examined. This function is required to accept a single argument of type
state_type.The output data type of the aggregate function is defined as the return type of this function. If you do not specify
ffunc, the ending state value is used as the aggregate’s result, and the output data type is determined bystate_type.initial_conditionThe initial value of the aggregate function’s state value. This is a literal constant ...