ARRAY_POSITION()

All functions > ARRAY > ARRAY_POSITION()

Returns the 1-based position of the first occurrence of an element in an array.

Signatures

Returns: The 1-based position of the first occurrence, or NULL if not found

ARRAY_POSITION(array: ARRAY<T>, element: T) → BIGINT
sql
ParameterTypeRequiredDescription
arrayARRAY<T>YesThe array to search in
elementTYesThe element to find in the array

Notes

  • Returns 1-based index (SQL standard)
  • Finds only the first occurrence of the element
  • Returns NULL if element is not found in the array
  • Performs exact match comparison (case-sensitive for strings)
  • Can find NULL values in arrays
  • Supports ARRAY<ROW> and ARRAY<ARRAY<T>>: element and array must share the exact same type; mismatched schemas raise a user error

See also

Examples

FeatureQL
SELECT
    -- Find element at position 3
    f1 := ARRAY_POSITION(ARRAY(1, 2, 3, 4), 3),
    -- Find string element
    f2 := ARRAY_POSITION(ARRAY('A', 'B', 'C'), 'B'),
    -- First occurrence only
    f3 := ARRAY_POSITION(ARRAY('apple', 'banana', 'apple'), 'apple'),
    -- Element not found
    f4 := ARRAY_POSITION(ARRAY(1, 2, 3), 5),
    -- Find NULL element
    f5 := ARRAY_POSITION(ARRAY(1, NULL::BIGINT, 3), NULL::BIGINT),
    -- Empty array
    f6 := ARRAY_POSITION(ARRAY()::BIGINT[], 1),
    -- First occurrence of duplicate
    f7 := ARRAY_POSITION(ARRAY(1, 2, 2, 3), 2)
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINTf5 BIGINTf6 BIGINTf7 BIGINT
321null2null2

Last update at: 2026/06/20 10:08:10