Spec-Zone .ru
спецификации, руководства, описания, API

23.3.2.2. UDF Calling Sequences for Aggregate Functions

This section describes the different functions that you need to define when you create an aggregate UDF. Section 23.3.2, "Adding a New User-Defined Function", describes the order in which MySQL calls these functions.

The xxx() function for an aggregate UDF should be declared the same way as for a nonaggregate UDF. See Section 23.3.2.1, "UDF Calling Sequences for Simple Functions".

For an aggregate UDF, MySQL calls the xxx() function after all rows in the group have been processed. You should normally never access its UDF_ARGS argument here but instead return a value based on your internal summary variables.

Return value handling in xxx() should be done the same way as for a nonaggregate UDF. See Section 23.3.2.4, "UDF Return Values and Error Handling".

The xxx_reset() and xxx_add() functions handle their UDF_ARGS argument the same way as functions for nonaggregate UDFs. See Section 23.3.2.3, "UDF Argument Processing".

The pointer arguments to is_null and error are the same for all calls to xxx_reset(), xxx_clear(), xxx_add() and xxx(). You can use this to remember that you got an error or whether the xxx() function should return NULL. You should not store a string into *error! error points to a single-byte variable, not to a string buffer.

*is_null is reset for each group (before calling xxx_clear()). *error is never reset.

If *is_null or *error are set when xxx() returns, MySQL returns NULL as the result for the group function.