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: Single element at the position indicated by index[key]

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

Notes

  • Uses index to map key to array position
  • Looks up key in index to find position
  • Returns element at that position from base array
  • Returns NULL if key not found in index
  • Useful for efficient lookups with pre-computed indexes

Examples

FeatureQL
SELECT
    f1 := ELEMENT_AT_KEY(INDEX_UNIQUE(ARRAY[ROW(1 AS k, 'a' AS v), ROW(2 AS k, 'b' AS v)] BY k), 2) -- Row at the index position for a key (INDEX_UNIQUE index)
;
Result
f1 ROW
{k: 2, v: b}

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