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.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
jpx1556733107962.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1184
lifecycle
previous
Product Category
Teradata Vantage™

When you pass parameters directly to a UDF, Teradata Database returns parameter metadata in a Statement Info parcel (see Teradata Call-Level Interface Version 2 Reference for Mainframe-Attached Systems or 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 Teradata Database can resolve the UDF with just a ? parameter passed directly to the UDF. Teradata Database 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, Teradata Database 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;