Example: CTE Result Set as Input to a Table Function - Advanced SQL Engine - Teradata Database

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

Suppose you have created these tables and table function.

     CREATE TABLE t1 (
       a1 INTEGER,
       b1 INTEGER);

     CREATE TABLE t2 (
       a2 INTEGER,
       b2 INTEGER);

     CREATE 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';

Use the temporary result set derived from the subquery in the WITH statement modifier as input to table function add2int in the FROM clause.

     WITH dt(a,b) AS (
       SELECT a1, b1
       FROM t1)
     SELECT addend1, addend2, mysum
     FROM dt, TABLE (add2int(dt.a, dt.b)) AS tf
     ORDER BY 1,2,3;