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

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

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);