16.20 - C Function Definition for the Transform Method - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Advanced SQL Engine
Teradata Database
Release Number
Release Date
April 2020
Content Type
Programming Reference
Publication ID
English (United States)

The following example implements transform functionality that allows Teradata Database to export a circle_t type as a VARCHAR(80). The format of the VARCHAR string is:


Null attributes are indicated by an absence of a value. For example, the format for a null radius is:


/* File: c_fromsql.c */

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void circle_t_FromSql( UDT_HANDLE    *circleUdt,
                       VARCHAR_LATIN *result,
                       char          sqlstate[6])
    INTEGER x, y, r;
    char y_str[11], r_str[11];
    VARCHAR_LATIN color[81];
    int nullIndicator;
    int length;

    /* Get each of the attributes and write them to the result string. */
    FNC_GetStructuredAttribute(*circleUdt, "x", &x, SIZEOF_INTEGER, &nullIndicator, &length);
    if (nullIndicator == 0)
        sprintf((char *)result, "%d:", x);
        strcpy((char *)result, ":");

    FNC_GetStructuredAttribute(*circleUdt, "y", &y, SIZEOF_INTEGER, &nullIndicator, &length);
    if (nullIndicator == 0) {
        sprintf(y_str, "%d", y);
        strcat((char *)result, y_str);
    strcat((char *)result, ":");

    FNC_GetStructuredAttribute(*circleUdt, "radius", &r, SIZEOF_INTEGER, &nullIndicator, &length);
    if (nullIndicator == 0) {
        sprintf(r_str, "%d", r);
        strcat((char *)result, r_str);
    strcat((char *)result, ":");

    FNC_GetStructuredAttribute(*circleUdt, "color", color, SIZEOF_VARCHAR_LATIN_WITH_NULL(80), &nullIndicator, &length);
    if (nullIndicator == 0)
        strcat((char *)result, (char *)color);