17.05 - Example: Upsert Update Using a Period Bound Function - 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)

Suppose you define the following row-partitioned table using the END Period bound function.

     CREATE SET TABLE testing.t33 (
       a INTEGER,
       b PERIOD(DATE),
       c INTEGER)
     PRIMARY INDEX (a)
     PARTITION BY CAST((END(b)) AS INTEGER);

This UPDATE upsert request inserts a new row into t33.

     UPDATE t33
      SET c = 1
         WHERE a = 20
         AND   END(b) = DATE '1901-02-25'
       ELSE INSERT INTO t33 (20, PERIOD(DATE '1901-02-24',
                             DATE '1901-02-25'), 1);