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: Multiple elements at the positions indicated by index[key]

ELEMENTS_AT_KEY(index: INDEX, key: T, base: ARRAY<ROW<T>>) → ARRAY<ROW<T>>
sql
ParameterTypeRequiredDescription
indexINDEXYesIndex to look up positions from
keyTYesKey to look up in the index
baseARRAY<ROW<T>>YesArray or array of rows to extract elements from

Notes

  • Uses index to map key to multiple array positions
  • Looks up key in index to find array of positions
  • Returns elements at those positions from base array
  • Returns empty array if key not found in index
  • Useful for one-to-many lookups with multi-valued indexes

Examples

FeatureQL
SELECT
    f1 := ELEMENTS_AT_KEY(INDEX_MULTI(ARRAY[ROW(1 AS k, 'a' AS v), ROW(1 AS k, 'b' AS v)] BY k), 1) -- All rows for a key (INDEX_MULTI index)
;
Result
f1 VARCHAR
[{k: 1, v: a}, {k: 1, v: b}]

Last update at: 2026/05/26 17:22:09