Example: Invoking Argument Data Types of Different Sizes - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

In this example, the UDF invocation argument data type (INTEGER) is not the same as that of the corresponding UDF parameter data type (BYTEINT) since the size of the argument data type is greater than the UDF parameter data type. Although the two data types are compatible, an INTEGER argument cannot fit inside a BYTEINT parameter, so an error is returned.

   CREATE FUNCTION test.MyUDF (a BYTEINT, b INT, c INT)
   RETURNS INT
   LANGUAGE SQL
   CONTAINS SQL
   DETERMINISTIC
   COLLATION INVOKER
   INLINE TYPE 1
   RETURN a * b * c;
   CREATE TABLE t1 (a1 INT, b1 INT);
   SELECT test.MyUDF(t1.a1, t1.b1, 2) FROM t1;

The following error is returned:

   Failure 5589: Function "test.MyUDF" does not exist.

To avoid the error, the caller must explicitly cast the value of t1.a1 to BYTEINT as follows:

   SELECT test.MyUDF(CAST(t1.a1 AS BYTEINT), t1.b1, 2) FROM t1;