17.10 - Usage Notes - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - Data Types and Literals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1143-171K
Language
English (United States)

Where TD_ANYTYPE is Useful

The TD_ANYTYPE data type is useful in:
  • Declaring routines (functions, methods, external stored procedures) that support parameters with differing precisions and character parameters with varying character sets.
  • Avoiding precision loss of decimal parameters due to truncation when the arguments do not match with the parameters in the function signature.
  • Reducing the number of overloaded routines needed to support routines that have constant parameter counts but differing parameter data types.
  • Declaring routines whose return data type is determined at runtime.

Rules

You can only specify TD_ANYTYPE as a data type for:
  • Input parameters in scalar, aggregate and table functions written in C, C++, or Java.
  • Result parameters in scalar and aggregate functions written in C, C++, or Java.
  • IN, INOUT, or OUT parameters in external stored procedures written in C, C++, or Java.
  • Input and output parameters in UDMs written in C or C++.

Restrictions

The TD_ANYTYPE type is not supported as a parameter type for:
  • Stored procedures
  • SQL UDFs
  • UDMs written in Java
TD_ANYTYPE cannot be used:
  • As the return type in table functions
  • To represent UDT parameters in Java routines

Declaring the Return Type of a TD_ANYTYPE Result Parameter

When invoking a UDF or UDM that is defined with a TD_ANYTYPE result parameter, you can use the RETURNS data type or RETURNS STYLE column expression clause to specify the desired return type. The column expression can be any valid table or view column reference, and the return data type is determined based on the type of the column.

For example:

SELECT (routine_name  (parameter_list) RETURNS  data_type);
SELECT (routine_name  (parameter_list) RETURNS STYLE  TableName.ColumnName);

The above queries invoke routine_name using the specified parameters and declare the return type to be data_type or the data type of the column, TableName.ColumnName.

You must enclose the UDF or UDM invocation in parenthesis if you use the RETURNS or RETURNS STYLE clause.

When invoking an external stored procedure that is defined with a TD_ANYTYPE OUT parameter, you can specify the RETURNS data typeor RETURNS STYLE column expression clause along with the OUT parameter in the CALL statement to indicate the desired return type of the OUT parameter.

For example:

CALL  procedure_name(parameter1,  out_parameter  RETURNS  data_type);
CALL  procedure_name(parameter1,  out_parameter  RETURNS STYLE  TableName.ColumnName);

The RETURNS or RETURNS STYLE clause is not mandatory as long as the routine also includes a TD_ANYTYPE input parameter. If you do not specify a RETURNS or RETURNS STYLE clause, then the data type of the first TD_ANYTYPE input argument is used to determine the return type of the TD_ANYTYPE result or OUT parameter. For character types, if the character set is not specified as part of the data type, then the default character set is used.

Note that the RETURNS and RETURNS STYLE clauses are only used to set the return type for a TD_ANYTYPE OUT parameter in external stored procedures. The data type of a TD_ANYTYPE INOUT parameter is determined by the data type of the corresponding input argument.