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

Examples

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

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19