Example 1 - Analytics Database - Teradata Vantage

SQL Operators and User-Defined Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-05
dita:mapPath
xub1628111590556.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
drp1544241916620
lifecycle
latest
Product Category
Teradata Vantage™

The following NEW VARIANT_TYPE expression creates a dynamic UDT with a single attribute named weight:

NEW VARIANT_TYPE (Table1.a AS weight)

In the next example, the NEW VARIANT_TYPE expression creates a dynamic UDT with a single attribute named height. In this example, no alias name is specified; therefore, the column name is used as the attribute name.

NEW VARIANT_TYPE (Table1.height)

In the next example, the first attribute is named height based on the column name. However, the second attribute is also named height based on the specified alias name. This is not allowed since attribute names must be unique; therefore, the system returns the error, “ERRTEQDUPLATTRNAME - "Duplicate attribute names in the attribute list. %VSTR", being returned to the user.”

NEW VARIANT_TYPE (Table1.height, Table1.a AS height)

This example shows a user-defined aggregate function with an input parameter named parameter_1 declared as VARIANT_TYPE data type. The SELECT statement calls the new function using the NEW VARIANT_TYPE expression to create a dynamic UDT with two attributes named a and b.

CREATE TYPE INTEGERUDT AS INTEGER FINAL;
CREATE FUNCTION udf_agch002002dynudt (parameter_1  VARIANT_TYPE)
RETURNS INTEGERUDT CLASS AGGREGATE (4) LANGUAGE C  NO SQL
EXTERNAL NAME   'CS!udf_agch002002dynudt!udf_agch002002dynudt.c'
PARAMETER STYLE SQL;
SELECT udf_agch002002dynudt(NEW VARIANT_TYPE (Tbl1.a AS a,
                                             (Tbl1.b + Tbl1.c) AS b))
FROM Tbl1;