17.10 - Example: Invoking an SQL UDF Within a Trigger Definition - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1144-171K
Language
English (United States)

This example invokes the SQL UDF common_value_expression from the WHEN clause of the definition of the row trigger trig_insert_after_update.

     CREATE TRIGGER trig_insert_after_update
       AFTER UPDATE OF b1 ON t1
       REFERENCING OLD AS OldRow NEW AS NewRow
     FOR EACH ROW
       WHEN (test.common_value_expression(OldRow.a1, NewRow.b1) >.10)
       INSERT INTO t2
       VALUES (NewRow.a1, NewRow.b1, NewRow.c1);

The next example invokes the SQL UDF common_value_expression in the triggered statement of the row trigger trig_insert.

     CREATE TRIGGER trig_insert 
       AFTER INSERT ON t1
       REFERENCING NEW AS n
     FOR EACH ROW (
       INSERT INTO t2 
       VALUES (n.a1, test.common_value_expression(n.b2, 1), n.c1); );