with_unique_keys

The with_unique_keys method returns a table that shares the underlying data and schema with the source table, but with the specified columns marked as its key columns, additionally indicating that each combination of key values identifies exactly one row.

Key columns are metadata used by consumers such as the Deephaven UI to identify which rows represent the same real-world entity. They do not affect the table's data. Use with_unique_keys when the key columns form a true primary key, so that selecting a row in the Deephaven UI never selects any other row. If more than one row can share the same key values, use with_keys instead.

with_unique_keys does not verify that the key values are actually unique; it only records that assumption for consumers of the table.

Syntax

Parameters

ParameterTypeDescription
colsUnion[str, Sequence[str]]

The key column name(s). Must name at least one existing column in the source table.

Returns

A table that shares the underlying data and schema with the source table, with the keyColumns attribute set to the specified column names and the uniqueKeys attribute set to True. If the source table already has this exact set of unique key columns, the source table itself may be returned.

Examples

In this example, every row of unique_keyed_table has a distinct Key1 value, so selecting a row in the Deephaven UI tracks only that row.

Unique keyed row selection