INSERT Duplicate Row Handling - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Duplicate row handling depends on how the table is defined. The system ignores trailing pad characters in character strings when comparing values for field or row duplication.

Table Definition Duplicate Row Insert Action
MULTISET with no UNIQUE constraints Inserted.
  • SET
  • MULTISET with UNIQUE constraints
Not inserted.

An error is returned to the requestor.

If inserting into an identity column table, this is true only when the column is defined WITH NO CYCLE. An error can occur if an attempt is made to cycle. The system can also return errors for other reasons, like uniqueness violations, before a duplicate row violation can be reported.

Duplicate Rows and INSERT ... SELECT

If an INSERT using a SELECT subquery creates duplicate rows, the result depends on the table definition:
  • Duplicate rows are permitted in a MULTISET set only if no UNIQUE constraints or UNIQUE indexes are defined on the table.
  • Duplicate rows are not permitted in a SET table.

The following table summarizes the restrictions on duplicate rows and INSERT ... SELECT:

Type of Table Duplicate Rows
MULTISET with no unique constraints Permitted.

Inserted duplicate rows are stored in the table.

MULTISET with unique constraints not permitted. An error message is returned to the requestor.

The following constraints are considered to be unique in Vantage:

  • Unique primary index
  • Unique secondary index
  • Primary key
  • UNIQUE column constraint
  • GENERATED ALWAYS identity column constraint.

For nontemporal tables, unique secondary indexes, primary keys, and UNIQUE constraints are all implemented internally as unique secondary indexes.

SET Not permitted.
  • In ANSI session mode, the system rejects the request and returns an error message to the requestor.

    If another error, such as violating a uniqueness constraint, occurs first, then the system returns that error to the requestor rather than a duplicate row message

  • In Teradata session mode, the database does the following.

    Rejects the duplicate rows in the transaction.

    Inserts the non-duplicate rows into the table.

    Does not return an error message to the requestor.

In Teradata session mode, If an INSERT ... SELECT request specifies a SAMPLE clause that selects a set of rows from a source MULTISET table, and inserts the rows into a target SET table, and the sampled row set contains duplicates, the number of rows inserted into the target SET table can be fewer than the number requested in the SAMPLE clause.

The condition occurs because SET tables reject attempts to insert duplicate rows. The result is that the INSERT portion of the INSERT ... SELECT operation inserts only distinct rows into SET target tables. Therefore, the number of rows inserted into the target table can be fewer than the number specified in the SAMPLE clause.

For example, if an INSERT ... SELECT request SAMPLE clause requests a sample size of 10 rows, and there are duplicate rows from the MULTISET source table in the collected sample, the system rejects the duplicate instances when it attempts to insert the sampled rows into the SET table and inserts only the distinct rows from the sample set. That is, you can request a sample of 10 rows, but the number of rows inserted into the target table can be fewer than 10 if there are duplicate rows in the sampled row set. The database does not return a warning or message.