Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
Returns the position of the first occurrence of a specified value in an array.
Syntax
array_position(<array>, <value>)
Arguments
Required
<array>: The array to search.<value>: The value to find (must match the array element type).
Returns
Returns an integer that represents the 1-based index of the first occurrence, or NULL if the value isn't found.
Considerations
- Returns NULL when the value isn't found.
- Position indexing is 1-based.
Examples
Find Element Position
Find the position of a value in an array.
SELECT array_position(array[1, 3, 4, 3], 3) AS position;
Returns 2, the index of the first occurrence of 3 in the array.
Value Not Found
Attempt to find a value that doesn't exist.
SELECT array_position(array[1, 3, 4, 3], 2) AS position;
Returns null because 2 isn't present in the array.