Passing Parameters to an SQL UDF - Advanced SQL Engine - Teradata Database

SQL Data Definition Language Detailed Topics

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
imq1591724555718.ditamap
dita:ditavalPath
imq1591724555718.ditaval
dita:id
B035-1184
lifecycle
previous
Product Category
Teradata Vantage™

When you pass parameters directly to a UDF, Vantage returns parameter metadata in a Statement Info parcel (see Teradata® Call-Level Interface Version 2 Reference for Mainframe-Attached Systems, B035-2417 for details). The rules for passing parameters to an external UDF or method also apply to SQL UDFs (see Rules for Using SQL UDFs and Function Calling Argument).

In this example, the SQL UDF is not overloaded, so Vantage can resolve the UDF with just a ? parameter passed directly to the UDF. Vantage returns the parameter metadata regarding the UDF parameter in the target position.

SELECT myudf(1, ?)
FROM t1;

In this example, the SQL UDF is overloaded, so you must explicitly cast the ? parameter to an acceptable value to enable the UDF to be resolved in Prepare mode. If you do not specify such a cast, Vantage cannot resolve the UDF, so the request aborts and the system returns an error to the requestor. For the purposes of parameter metadata, the data type field of the returned metadata is the result type of the cast.

SELECT myudf(1, CAST(? AS INTEGER), col3)
FROM t1;