Extending a built-in aggregate
About this task
To extend a built-in aggregate function with a C user-defined function:
Procedure
- Determine the appropriate operator function that you must
overload to implement the built-in aggregate function you want.
For a list of built-in aggregate functions and the associated operator functions to overload, see the section on aggregate functions in the Informix® User-Defined Routines and Data Types Developer's Guide.
- Write the C UDR that implements the required operator function
for the data type that you want the aggregate to handle.
To extend built-in aggregates so that they handle user-defined data types, write an operator function that accepts the user-defined data type as an argument. Compile the C UDR and link it into a shared-object file.
- Register the overloaded operator function with the CREATE FUNCTION statement.
- Use the newly extended aggregate on the data.
Example
Suppose you want to use the SUM aggregate on complex numbers,
which are stored in the following user-defined data type: a named
row type named complexnum_t. The following code fragment shows
the CREATE ROW TYPE statement that registers the complexnum_t named
row type.
The following sections show how to extend the SUM aggregate on the complexnum_t named row type.