Example 2 - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

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
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantage™

The following table function "add2int" takes two integers as input and returns the two integers and their summation.

   CREATE TABLE t1 (a1 INTEGER, b1 INTEGER);
   CREATE TABLE t2 (a2 INTEGER, b2 INTEGER);
   REPLACE FUNCTION add2int
      (a INTEGER,
       b INTEGER)
   RETURNS TABLE
      (addend1 INTEGER,
       addend2 INTEGER,
       mysum INTEGER)
   SPECIFIC add2int
   LANGUAGE C
   NO SQL
   PARAMETER STYLE SQL
   NOT DETERMINISTIC
   CALLED ON NULL INPUT
   EXTERNAL NAME 'CS!add3int!add2int.c';
   /* Query Q1 */
   WITH dt(a1, b1) AS
   ( SELECT a1, b1
     FROM t1
     UNION ALL
     SELECT a2, b2
     FROM t2
   )
   SELECT * 
   FROM TABLE (add2int(dt.a1, dt.b1) 
   HASH BY b1 
   LOCAL ORDER BY b1) tf;