Example: Aggregate Function with Parameter Style SQL - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-03-30
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
qnu1472247494689
lifecycle
latest
Product Category
Teradata Vantage™

This example declares an aggregate function that uses parameter style SQL:

/*****  C source file name: STD_DEV.c  *****/
   
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
#include <math.h>
 
void STD_DEV ( FNC_Phase     phase,
               FNC_Context_t *fctx,
               FLOAT         *x,
               FLOAT         *result,
               int           *x_i,
               int           *result_i,
               char          sqlstate[6],
               SQL_TEXT      *function_name,
               SQL_TEXT      *specific_name,
               SQL_TEXT      error_message[257])
{
     ...
}

The corresponding CREATE FUNCTION statement looks like this:

CREATE FUNCTION STD_DEV(x FLOAT)
RETURNS FLOAT
CLASS AGGREGATE
LANGUAGE C
NO SQL
PARAMETER STYLE SQL
EXTERNAL;