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
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
vnq1596660420420.ditamap
dita:ditavalPath
hoy1596145193032.ditaval

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;