INDEX_UNIQUE()
All functions > ARRAY OF ROWS > INDEX_UNIQUE()
Returns an index unique computed from the given array and key.
Signatures
Returns: Map from key values to array positions (1-based)
INDEX_UNIQUE(base: ARRAY<ROW<T>>, key: FIELD) → INDEX sql
| Parameter | Type | Required | Description |
|---|---|---|---|
base | ARRAY<ROW<T>> | Yes | Array of rows to index |
key | FIELD | Yes | Field name to use as lookup key |
Notes
- Creates a unique index mapping key values to array positions
- Each key maps to at most one position (the last occurrence if duplicates exist)
- Returns 1-based array indices
- NULL keys are excluded from the index
- Useful for efficient lookups with ELEMENT_AT_KEY
- If duplicate keys exist, keeps the last occurrence
- Use INDEX_MULTI for keys with multiple values
Examples
FeatureQL
SELECT
f1 := INDEX_UNIQUE(ARRAY[ROW(1 AS k, 'a' AS v), ROW(2 AS k, 'b' AS v)] BY k) -- Map each key to a single 1-based row index (equiv skipped: MAP has no FeatureQL literal)
;Result
| f1 VARCHAR |
|---|
| {1: 1, 2: 2} |
On this page