DECIMAL / NUMERIC - 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™

C Data Type Definition

typedef signed char DECIMAL1;
typedef short       DECIMAL2;
typedef int         DECIMAL4;

typedef signed char NUMERIC1;
typedef short       NUMERIC2;
typedef int         NUMERIC4;

typedef struct
{
    unsigned int low;
    int          high;
} DECIMAL8, NUMERIC8;

typedef struct
{
    unsigned int int1;
    unsigned int int2;
    unsigned int int3;
    int          int4;
} DECIMAL16, NUMERIC16;

Usage

The size of the SQL DECIMAL(n,m) or NUMERIC(n,m) type determines which C type to use.

Size C Type
1 ≤ n ≤ 2 DECIMAL1 or NUMERIC1
3 ≤ n ≤ 4 DECIMAL2 or NUMERIC2
5 ≤ n ≤ 9 DECIMAL4 or NUMERIC4
10 ≤ n ≤ 18 DECIMAL8 or NUMERIC8
18 < n DECIMAL16 or NUMERIC16

The size of the SQL type also determines the range of values for a DECIMAL input argument or return argument. For example, if a CREATE FUNCTION statement defines a DECIMAL(1,0) input argument, the range of values for the argument is -9 to 9. A value outside the valid range of values produces a numeric overflow error. For details on DECIMAL types, see Teradata Vantage™ - Data Types and Literals, B035-1143.

For a DECIMAL type that can be represented as variable length, the best practice is to specify the DECIMAL that can handle the largest value that the C code can handle.

This example uses DECIMAL in a UDF definition and C function declaration.

SQL Function Definition Equivalent C Function Declaration
CREATE FUNCTION F1 (
  A DECIMAL(5,0) )
RETURNS DECIMAL(5,0)
 ...;
void f1( DECIMAL4 *a,
         DECIMAL4 *result,
   ... )
{  ... }