Teradata Parallel Data Pump
Teradata Parallel Data Pump Reference - Teradata Developer ...
Teradata Parallel Data Pump Reference - Teradata Developer ...
- 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 />
DML<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 />
(ItemNbr INTEGER NOT NULL,<br />
SaleDate DATE FORMAT 'MM/DD/YYYY' NOT NULL,<br />
ItemCount INTEGER)<br />
PRIMARY INDEX (ItemNbr);<br />
It is assumed that the table has been populated with the following data:<br />
INSERT INTO Sales (10, '05/30/2005', 1);<br />
Assume that there exists a table called NewSales that has the same column definitions as those<br />
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 />
.Dml label upsertdml do insert for missing update rows;<br />
UPDATE Sales SET ItemCount = ItemCount + 1 WHERE (ItemNbr = 10 AND<br />
SaleDate = '05/30/2005');<br />
INSERT INTO NewSales (10,'05/30/2005', 1);<br />
A rule of an upsert statement is that only one single table is processed for the statement.<br />
Because the tables, Sales and NewSales, are not the same for the upsert statement, an error is<br />
returned, indicating that the name of the table must be the same for both the UPDATE and<br />
the 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 the UPDATE part and the INSERT part of the statement.<br />
.Dml label upsertdml do insert for duplicate update rows;<br />
UPDATE Sales SET ItemCount = ItemCount + 1 WHERE (ItemNbr = 10 AND<br />
SaleDate = '05/30/2005');<br />
INSERT INTO Sales (20,'05/30/2005', 1);<br />
The primary index values for the UPDATE and the INSERT must be the same. Otherwise, we<br />
would be looking at two different rows: one for UPDATE and the other for INSERT, which is<br />
not the purpose of an upsert. An error is returned for the upsert statement because the<br />
specified primary index values of 10 and 20 are not the same (the primary index value must be<br />
the same for both the UPDATE and the INSERT).<br />
Example 3 (Valid Upsert UPDATE)<br />
This example demonstrates a successful upsert statement where a row gets updated.<br />
.Dml label upsertdml do insert for missing update rows;<br />
UPDATE Sales SET ItemCount = ItemCount + 1 WHERE (ItemNbr = 10 AND<br />
SaleDate = '05/30/2005');<br />
INSERT INTO Sales (10, '05/30/2005', 1);<br />
<strong>Teradata</strong> <strong>Parallel</strong> <strong>Data</strong> <strong>Pump</strong> Reference 127