ARRAY_FIRST
Returns the first element in the given array for which the given <func>
function returns something other than 0
. The <func>
argument must be included.
Syntax
ARRAY_FIRST(<func>, <arr>)
Parameter | Description |
---|---|
<func> | A Lambda function used to check elements in the array. |
<arr> | The array evaluated by the function. |
Examples
SELECT
ARRAY_FIRST(x -> x > 2, [ 1, 2, 3, 9 ]) AS res;
Returns: 3
In the example below, the third index is returned because it is the first that evaluates to blue
.
SELECT
ARRAY_FIRST(x, y -> y = 'blue',
[ 1, 2, 3, 4 ],
[ 'red', 'green', 'blue' ,'blue' ]
)
AS res;
Returns: 3