ARRAY_FIND
Returns the ordinal position of a specified element in an array, -1 if not found, or NULL if either the array or specified element is NULL.
Behavior Type
Syntax
ARRAY_FIND(array, val_to_find)
Supported Data Types
1D arrays of any primitive type.
Example
=> SELECT array_find(array[1,2,3],2);
array_find
------------
1
(1 row)
The function returns the first occurrence of the specified element. However, nothing ensures that value is unique in the array.
=> SELECT array_find(ARRAY[1,2,7,5,7],7);
array_find
------------
2
(1 row)
The function returns -1 if the specified element is not found.
=> SELECT array_find(ARRAY[1,3,5,7],4);
array_find
------------
-1
(1 row)