Specifies the primary key for a delta stream or window.
PRIMARY KEY (column [,...]) | PRIMARY KEY DEDUCED
column | The name of a column in the element's schema |
A primary key uniquely identifies a record, and is required for windows and delta streams.
The primary key is normally treated as "strict." Any records that violate consistency rules, such as an insert of an existing record, or update or delete for a nonexistent record, are discarded and reported in the log.
The primary key is treated as "lax" when a keep policy is placed on a window. The expiration of records caused by the KEEP clause creates inconsistencies with incoming records. An insert on an existing record is treated as an update, and an update on a nonexistent record is treated as an insert. A delete on a nonexistent record is silently ignored (as safedelete). This behavior manifests when two records in a chain have expiry policies, and it is apparent that the target window has a smaller expiry period.
An explicitly defined primary key uses the PRIMARY KEY clause and refers to one or more columns of the window or delta stream's schema. When a primary key is specified, the engine enforces the constraint, and erroneous operations are flagged as bad records and discarded at runtime. To avoid this issue, ensure the primary key is defined correctly.
If the primary key is specified as PRIMARY KEY DEDUCED, the compiler automatically deduces the primary key. If the primary key cannot be deduced, a compilation error is generated.