Using a pointer-valued state for a UDA
A pointer-valued state uses the POINTER data type as the aggregate state.
About this task
To use a pointer-valued state for a UDA
Procedure
- Write the appropriate aggregate support functions so that
they handle a pointer-valued state.
Declare the state parameters and return values of the aggregate support functions to use the mi_pointer data type. Information on how to handle state management of a pointer-valued state follows.
- Register the aggregate support functions with the CREATE
FUNCTION statement.
Specify the POINTER data type for the state parameters and return values in the function signatures of the aggregate support functions.
Results
void *
- The INIT function can allocate and initialize the aggregate state.
The INIT function must also allocate any related resources that the aggregate state might need. Keep in mind that the database server does not interpret the contents of the pointer-valued state. It cannot manage any objects that the state type might reference. Therefore, use states with embedded pointers with caution.
- The ITER function must perform an in-place update to initialize
or modify a pointer-valued state.
After you allocate the pointer-valued state, the database server passes a pointer to this state to the other aggregate support functions. Initialize or update the pointer-valued state only with an in-place update. For more information, see When to allocate and deallocate a state.
- The FINAL function can handle deallocation of resources that the
INIT function has set up.
For a pointer-valued state, the FINAL function must always deallocate the aggregate state. If your INIT support function has allocated related resources that the aggregate state uses, make sure that the FINAL function deallocates these resources.