withUniqueKeys
The withUniqueKeys 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 withUniqueKeys 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 withKeys instead — but note that withKeys does not clear the uniqueKeys attribute on its own. See the note on withKeys for converting a table that already has it set.
withUniqueKeys 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 |
|---|---|---|
| columns | String... | 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,whereIn, andwhereNotInsortandsortDescendingreverseflattenupdateViewandlazyUpdatenaturalJoinandexactJoin
Other operations that build a new result from the table's data — including select, update, view, join, and dropColumns — clear both attributes. Call withKeys or withUniqueKeys again on the result to restore them.
withAttributes and withoutAttributes 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. retainingAttributes works the other way around — it drops every attribute except the ones you name, so keyColumns and uniqueKeys only survive it if you explicitly include them.
Examples
In this example, every row of uniqueKeyedTable has a distinct Key1 value, so selecting a row in the Deephaven UI tracks only that row.
