SQL Definition - 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™

Here is the SQL definition of a color_t distinct UDT and a circle_t structured UDT.

CREATE TYPE color_t
   AS VARCHAR(30)
   FINAL;

CREATE TYPE circle_t
   AS (x INTEGER, y INTEGER, radius INTEGER, color color_t)
   NOT FINAL;

The following CREATE FUNCTION statements install the functions:

CREATE FUNCTION circle_t_ToSql( p1 VARCHAR(80) )
   RETURNS circle_t
   NO SQL
   PARAMETER STYLE TD_GENERAL
   DETERMINISTIC
   LANGUAGE C
   EXTERNAL NAME 'CS!c_tosql!udfsrc/c_tosql.c!F!circle_t_ToSql';

CREATE FUNCTION circle_t_FromSql( p1 circle_t )
   RETURNS VARCHAR(80)
   NO SQL
   PARAMETER STYLE TD_GENERAL
   DETERMINISTIC
   LANGUAGE C
   EXTERNAL NAME 'CS!c_fromsql!udfsrc/c_fromsql.c!F!circle_t_FromSql';

CREATE FUNCTION circle_t_Ordering( p1 circle_t )
   RETURNS FLOAT
   SPECIFIC circle_t_Ordering
   NO SQL
   PARAMETER STYLE SQL
   DETERMINISTIC
   LANGUAGE C
   EXTERNAL NAME 'CS!c_order!udfsrc/c_order.c!F!circle_t_Ordering';

The following statement registers the circle_t_ToSql and circle_t_FromSql functions as transform routines for the circle_t UDT:

CREATE TRANSFORM FOR circle_t
   circle_t_IO (TO SQL WITH SPECIFIC FUNCTION circle_t_ToSql,
      FROM SQL WITH SPECIFIC FUNCTION circle_t_FromSql);

The following statement registers the circle_t_Ordering function as an ordering routine for the circle_t UDT:

CREATE ORDERING FOR circle_t
   ORDER FULL BY MAP WITH SPECIFIC FUNCTION circle_t_Ordering;