17.05 - Example: Using the BEGIN Period Bound Function as a Condition When Merging Into a RPPI Table - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)

Assume you define the following two tables.

     CREATE SET TABLE testing.t11 (
       a INTEGER,
       b DATE FORMAT 'YY/MM/DD',
       c DATE FORMAT 'YY/MM/DD')
     PRIMARY INDEX (a);

     CREATE SET TABLE testing.t12 (
       a INTEGER,
       b PERIOD(DATE),
       c INTEGER)
     PRIMARY INDEX (a)
     PARTITION BY RANGE_N((BEGIN(b) BETWEEN DATE '2009-01-01'
                                    AND     DATE '2011-12-31'
                                    EACH INTERVAL '1' MONTH);

The following MERGE request merges rows from t11 in to t12.

     MERGE INTO t12
       USING t11
       ON  t12.a = t11.a
       AND BEGIN (t12.b) = t11.b
     WHEN MATCHED THEN
       UPDATE SET c= 4
     WHEN NOT MATCHED THEN
       INSERT VALUES (t11.a, PERIOD(t11.b), 4);