Extending a built-in aggregate

About this task

To extend a built-in aggregate function with a C user-defined function:

Procedure

  1. 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.

  2. 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.

  3. Register the overloaded operator function with the CREATE FUNCTION statement.
  4. 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.
Figure 1: A named row type to hold a complex number
CREATE ROW TYPE complexnum_t
   (real_part SMALLFLOAT,
   imaginary_part SMALLFLOAT);

The following sections show how to extend the SUM aggregate on the complexnum_t named row type.