ELEMENTS_AT_KEY()
All functions > ARRAY OF ROWS > ELEMENTS_AT_KEY()
Returns multiple elements at the given key from the given index, array or array of rows.
Signatures
Returns: Every row of the indexed array with this key, in array order
ELEMENTS_AT_KEY(index, key) → ARRAY<ROW<T>> sql
| Parameter | Type | Required | Description |
|---|---|---|---|
index | INDEX | Yes | Index built with INDEX_MULTI(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
- Requires an
INDEX_MULTIindex (UE/ELEMENTS-AT-KEY-REQUIRES-MULTI-INDEX otherwise) - Returns an empty array 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
-- All rows for a key (INDEX_MULTI index)
f1 := ELEMENTS_AT_KEY(
INDEX_MULTI(ARRAY(ROW(1 AS k, 'a' AS v), ROW(1 AS k, 'b' AS v)) BY k),
1
)
;Result
| f1 VARBINARY |
|---|
| [{k: 1, v: a}, {k: 1, v: b}] |
On this page