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
| Parameter | Type | Required | Description |
|---|---|---|---|
array | ARRAY<T> | Yes | The array to search in |
element | T | Yes | The 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 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT | f5 BIGINT | f6 BIGINT | f7 BIGINT |
|---|---|---|---|---|---|---|
| 3 | 2 | 1 | null | 2 | null | 2 |
On this page