16.20 - Creating General Global Functions - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

One way to create a general global function is to supply the code in a C/C++ function for the first UDF you create.

For example, suppose you have the following general global function:

/*****  Source code filename: global1.c  *****/
int global1( char *text1)
{
   ...
}

The C code for the first UDF declares the general global function as external, and looks like this:

/*****  Source code filename: udf1.c  *****/
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
 
external global1(char *text1);
   
void udf1(CHARACTER *a, INTEGER *result,
          ... )
{
   int global_result;
 
   global_result = global1(a);
   ... 
   
}

The corresponding CREATE FUNCTION statement must specify the source for the general global function and the first UDF:

CREATE FUNCTION UDF1(A CHAR(30) CHARACTER SET LATIN)
RETURNS INTEGER
  ...
EXTERNAL NAME 'CS!global1!global1.c!CS!udf1!udf1.c';