17.05 - Example: Logging MERGE Errors - 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)

The following MERGE request logs all error types, including data errors, referential integrity errors, and USI errors, with an error limit of 100 errors.

     MERGE INTO tgttbl AS t1
     USING  (SELECT c1,c2,c3
             FROM srctbl) AS t2
       ON t1.c1=t2.c1
     WHEN MATCHED THEN
       UPDATE SET t1.c2=t2.c2 + t1.c2,  t1.c3=t2.c3
     WHEN NOT MATCHED THEN
       INSERT INTO t1 VALUES (t2.c1, t2.c2, t2.c3)
     LOGGING ERRORS WITH LIMIT OF 100;