Numeric Overflow in C/C++ UDFs | SQL External Routine Programming | Vantage - Overflow and Numeric Arguments in C/C++ UDFs - Teradata Vantage - Analytics Database

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
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ā„¢

Rather than making an assignment that results in a loss of significant digits, Vantage reports an overflow error.

Avoid numeric overflow in a C or C++ function by defining the largest decimal data type the function can handle.

For example, consider a scalar function that takes a DECIMAL(2,0) argument:

CREATE FUNCTION UDF_SMLDEC( p1 DECIMAL(2,0) )
RETURNS DECIMAL(2,0)
LANGUAGE C
NO SQL
PARAMETER STYLE TD_GENERAL
EXTERNAL;

Passing a number with a maximum of two digits is successful:

SELECT UDF_SMLDEC(99);

An attempt to pass a number larger than 99 or smaller than -99 is an error.

SELECT UDF_SMLDEC(100);

Result:

Failure 2616 Numeric overflow occurred during computation.

Fractional numeric data passed or returned that does not fit during assignment is rounded according to the Teradata rounding rules. See Teradata Vantageā„¢ - Data Types and Literals, B035-1143.