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 — but note that with_keys does not clear the uniqueKeys attribute on its own; see the note on with_keys for converting a table that already has it set.
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
| Parameter | Type | Description |
|---|---|---|
| cols | Union[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.
Preserved through table operations
The keyColumns and uniqueKeys attributes are preserved by:
where,where_in,where_not_in, andwhere_one_ofsortandsort_descendingreverseflattenupdate_viewandlazy_updatenatural_joinandexact_join
Other operations that build a new result from the table's data — including select, update, view, join, and drop_columns — clear both attributes. Call with_keys or with_unique_keys again on the result to restore them.
with_attributes and without_attributes are a separate case: they preserve every attribute they aren't explicitly asked to add or remove, so keyColumns and uniqueKeys survive them unless you target those specific keys.
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.
