25.09.2015 Views

Teradata Parallel Data Pump

Teradata Parallel Data Pump Reference - Teradata Developer ...

Teradata Parallel Data Pump Reference - Teradata Developer ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: <strong>Teradata</strong> T<strong>Pump</strong> Commands<br />

UPDATE Statement and Atomic Upsert<br />

<strong>Teradata</strong> T<strong>Pump</strong> changes this syntax into Atomic upsert syntax by replacing the semicolon<br />

between the UPDATE and INSERT statements with an ELSE keyword to convert the statement<br />

pair into a single Atomic upsert statement.<br />

If user-created macros are used in place of the UPDATE and INSERT statements, <strong>Teradata</strong><br />

T<strong>Pump</strong> generates:<br />

EXEC ELSE EXEC ;<br />

because this statement does not conform to Atomic upsert syntax used by <strong>Teradata</strong> T<strong>Pump</strong>.<br />

Atomic Upsert Examples<br />

This section describes several examples that demonstrate how the Atomic upsert feature<br />

works, including cases where errors are detected and returned to the user. All of the examples<br />

use the same table, called Sales, as shown below:<br />

CREATE TABLE Sales, FALLBACK,<br />

(ItemNbrINTEGER NOT NULL,<br />

SaleDateDATE FORMAT 'MM/DD/YYYY' NOT NULL,<br />

ItemCountINTEGER)<br />

PRIMARY INDEX (ItemNbr);<br />

Assume that the table has been populated with the following data:<br />

INSERT INTO Sales (10, '05/30/2005', 1);<br />

A table called NewSales has the same column definitions as those of table Sales.<br />

Example 1 (Error: different target tables)<br />

This example demonstrates an upsert statement that does not specify the same table name for<br />

the UPDATE part and the INSERT part of the statement.<br />

UPDATE Sales SET ItemCount = ItemCount + 1 WHERE (ItemNbr = 10 AND<br />

SaleDate = '05/30/2005') ELSE INSERT INTO NewSales (10, '05/30/2005',<br />

1);<br />

A rule of an upsert is that only one single table is processed for the statement. Because the<br />

tables, Sales and NewSales, are not the same for the upsert statement, an error is returned to<br />

the user indicating that the name of the table must be the same for both the UPDATE and the<br />

INSERT.<br />

Example 2 (Error: different target rows)<br />

This example demonstrates an upsert statement that does not specify the same primary index<br />

value for both the UPDATE and INSERT parts of the statement.<br />

UPDATE Sales SET ItemCount = Itemcount + 1 WHERE (ItemNbr = 10 AND<br />

SaleDate = '05/30/2005') ELSE INSERT INTO Sales (20, '05/30/2005', 1);<br />

The primary index values for the UPDATE and the INSERT must be the same. In this case, an<br />

error is returned to the user indicating that the primary index value must be the same for both<br />

the UPDATE and the INSERT.<br />

192 <strong>Teradata</strong> <strong>Parallel</strong> <strong>Data</strong> <strong>Pump</strong> Reference

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!