ARRAY_LOOKUP(...)

All functions > ARRAY > ARRAY_LOOKUP(...)

Returns the value corresponding to a lookup key using parallel key-value arrays.

Signatures

Returns: The value at the same position as the key

ARRAY_LOOKUP(lookup_key: T, keys: ARRAY<T>, values: ARRAY<U>) → U
sql
ParameterTypeRequiredDescription
lookup_keyTYesThe key to search for
keysARRAY<T>YesArray of keys
valuesARRAY<U>YesArray of values (parallel to keys)

Notes

  • Uses two parallel arrays: one for keys, one for values
  • Returns the value at the same index where the key is found
  • Returns NULL if key is not found
  • Only returns the first match if key appears multiple times
  • Arrays must be same length

See also

Examples

FeatureQL
SELECT
    f1 := ARRAY_LOOKUP('b', ARRAY('a', 'b', 'c'), ARRAY(10, 20, 30)), -- Find value by key in parallel arrays
    f2 := ARRAY_LOOKUP('x', ARRAY('a', 'b', 'c'), ARRAY(10, 20, 30)), -- Returns NULL when key is not found
    f3 := ARRAY_LOOKUP(2, ARRAY(1, 2, 3), ARRAY('first', 'second', 'third')), -- Numeric keys with string values
    f4 := ARRAY_LOOKUP('a', ARRAY('a', 'a', 'b'), ARRAY(1, 2, 3)) -- Returns first match when key appears multiple times
;
Result
f1 BIGINTf2 BIGINTf3 VARCHARf4 BIGINT
20NULLsecond1

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