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 BY key ) → INDEX sql
| Parameter | Type | Required | Description |
|---|---|---|---|
base | ARRAY<ROW<T>> | Yes | Array of rows to index |
key | FIELD | Yes | Field of the rows 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
- INDEX_UNIQUE declares one row per key: literal rows that repeat a key raise UE/INDEX-UNIQUE-DUPLICATE-KEY; a false declaration on data keeps the last occurrence
- Use INDEX_MULTI for keys with multiple values
- An index stays inside the query: returning it raises UE/INDEX-OUTPUT-NOT-SUPPORTED
Availability
| Status | Backends |
|---|---|
| Not available | mysql |
See also
Examples
FeatureQL
RETURN
-- One row per key. An index stays inside the query: look it up, do not return it
f1 := ELEMENT_AT_KEY(
INDEX_UNIQUE(ARRAY(ROW(1 AS k, 'a' AS v), ROW(2 AS k, 'c' AS v)) BY k),
1
)
;Result
| f1 ROW |
|---|
| {k: 1, v: a} |
On this page