17.10 - Producing the Final Group Result - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

During the AGR_FINAL aggregation phase, a UDF produces the final result for the group. The function must set the result argument to the final value.

The storage area pointed to by interim1 in the FNC_Context_t argument points to the aggregate storage area for the group. The function uses the interim1 pointer to calculate the final value and return it in the result argument.

In the standard deviation example, the function can use the following statements to calculate the final value:

FLOAT term2    = s1->x_sum / s1->n;
FLOAT variance = (s1->x_sq / s1->n) - (term2 * term2);

The following statement sets the result argument to the final value of the standard deviation:

*result = sqrt(variance);