Defining the user-defined aggregate
You can define the user-defined aggregate before you create the C implementation of the aggregate support functions. However, you must ensure that the names of the C functions match the names in the CREATE FUNCTION statements that register them.
About this task
To define a user-defined aggregate in a database with SQL
Procedure
- Register the user-defined aggregate in the database with the CREATE AGGREGATE statement
- Register the aggregate support functions in the database with the CREATE FUNCTION statement
Results
The development steps for a UDA list the definition of the UDA after the aggregate support functions are written. However, the CREATE AGGREGATE statement does not verify that the aggregate support functions it lists were registered nor does the CREATE FUNCTION statement verify that the executable C code exists.
Suppose that the INIT, ITER, COMBINE, and FINAL aggregate support functions for the SQSUM1 aggregate are compiled and linked into a shared-object module named sqsum.
On UNIX™ or Linux™, the executable code for the SQSUM1 aggregate support functions would be in a shared library named sqsum.so.
The registered names of the aggregate support functions must match the names that the CREATE AGGREGATE statement lists. For example, in Registering the aggregate support functions for SQSUM1 to handle INTEGER, a CREATE FUNCTION statement registers the INIT support function as init_sqsum1, which is the same name that the INIT option lists in the CREATE AGGREGATE statement (see Registering the SQSUM1 User-Defined Aggregate).
In addition, the CREATE FUNCTION for the INIT support function must include the HANDLESNULLS routine modifier so that the database server can pass the INIT function the dummy NULL-valued argument.
For more information about the use of the CREATE AGGREGATE and CREATE FUNCTION statements to define user-defined aggregates, see the chapter on aggregates in the Informix® User-Defined Routines and Data Types Developer's Guide. For the syntax of these statements, see the Informix® Guide to SQL: Syntax.