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 />

Example 3 (Error: unqualified primary index)<br />

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

WHERE clause.<br />

UPDATE Sales SET ItemCount = ItemCount + 1 WHERE SaleDate = '05/30/2005'<br />

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

When the primary index is not fully specified in the UPDATE of an upsert statement, an allrow<br />

scan to find rows to update might result. This is again not the purpose of upsert, and an<br />

error is returned to the user.<br />

Example 4 (Error: missing ELSE)<br />

This example demonstrates an upsert statement with a missing ELSE keyword.<br />

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

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

Example 5 (Error: INSERT-SELECT)<br />

This example demonstrates an upsert statement that specifies INSERT … SELECT.<br />

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

SaleDate = '05/30/2005') ELSE INSERT INTO Sales SELECT * FROM NewSales<br />

WHERE (ItemNbr = 10 AND SaleDate = '05/30/2005');<br />

The INSERT part of an upsert may not use a subquery to specify any of the inserted values. In<br />

this case, a syntax error is returned.<br />

Example 6 (Error: UPDATE-FROM)<br />

This example demonstrates an upsert statement that specifies UPDATE-FROM.<br />

UPDATE Sales FROM NewSales SET Sales.ItemCount = NewSales.ItemCount<br />

WHERE Sales.ItemNbr = NewSales.ItemNbr ELSE INSERT INTO Sales (10, '05/<br />

30/2005', 1);<br />

The SET clause may not use a FROM clause table reference in the expression for the updated<br />

value for a column, and an error is returned.<br />

Example 7 (Error: UPDATE-WHERE SUBQUERIES)<br />

This example demonstrates an upsert statement that specifies UPDATE-WHERE<br />

SUBQUERIES.<br />

UPDATE Sales SET ItemCount = ItemCount + 1 WHERE ItemNbr IN (SELECT<br />

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

The WHERE clause of the UPDATE may not use a subquery for any purpose. In this case,<br />

error ERRTEQUPSCOM is returned.<br />

Example 8 (Error: UPDATE-PRIMARY INDEX)<br />

This example demonstrates an upsert statement that tries to update a primary index value.<br />

UPDATE Sales SET ItemNbr = 20 WHERE (ItemNbr = 10 AND SaleDate = '05/30/<br />

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

Unreasonable updates or updates that change the primary index values are not allowed in an<br />

upsert statement, and an error is returned.<br />

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

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

Saved successfully!

Ooh no, something went wrong!