ELEMENT_AT_KEY()
All functions > ARRAY OF ROWS > ELEMENT_AT_KEY()
Returns one element at the given key from the given index, array or array of rows.
Signatures
Returns: The row of the indexed array for this key
ELEMENT_AT_KEY(index, key) → ROW<T> sql
| Parameter | Type | Required | Description |
|---|---|---|---|
index | INDEX | Yes | Index built with INDEX_UNIQUE(array BY field) |
key | T | Yes | Value of the indexed field to look up |
Notes
- The index remembers the array it was built from: pass only the index and the key
- Returns NULL if the key is not in the index
- Build the index once and reuse it for several lookups; it is faster than filtering with
TRANSFORM()each time
Availability
| Status | Backends |
|---|---|
| Not available | mysql |
See also
Examples
FeatureQL
RETURN
-- Row at the index position for a key (INDEX_UNIQUE index)
f1 := ELEMENT_AT_KEY(
INDEX_UNIQUE(ARRAY(ROW(1 AS k, 'a' AS v), ROW(2 AS k, 'b' AS v)) BY k),
2
)
;Result
| f1 ROW |
|---|
| {k: 2, v: b} |
On this page