Setting the Value of a Distinct UDT Result | Teradata Vantage - Setting the Value of a Distinct UDT Result - 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
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™

To set the value of a distinct UDT that is defined to be the result of a UDF, follow these steps.

IF the distinct type … THEN …
does not represent a LOB
  1. Allocate a buffer using the C data type that maps to the underlying type of the distinct UDT.
  2. Place the return value into the buffer.
  3. Call FNC_SetDistinctValue to set the value of the UDT to the return value in the buffer you allocated.
represents a LOB
  1. Declare a LOB_RESULT_LOCATOR to hold the locator of the distinct type.
  2. Call FNC_GetDistinctResultLob to set the LOB_RESULT_LOCATOR to the locator of the distinct UDT.
  3. Follow the steps in Appending Data to a Large Object Result to append the return data using the LOB locator.

For detailed information on FNC_SetDistinctValue and FNC_GetDistinctResultLob, see C Library Functions.

The following code excerpt sets the value of a distinct UDT that represents a FLOAT:

void meters_t_toFeet( UDT_HANDLE    *metersUdt,
                      UDT_HANDLE    *resultFeetUdt,
                      char           sqlstate[6])
{
    FLOAT value;
    int length;
    /* Get the value of metersUdt. */
    FNC_GetDistinctValue(*metersUdt, &value, SIZEOF_FLOAT, &length);
    /* Convert meters to feet and set the result value */
    value *= 3.28;
    FNC_SetDistinctValue(*resultFeetUdt, &value, SIZEOF_FLOAT);

    ...
}