Returns whether any element in an array satisfies a predicate condition.
Syntax
boolean any_match(array<T> <a>, function<T, boolean> <predicate>)Parameters
| Parameter | Required | Description |
|---|---|---|
a | Yes | The array to evaluate. T specifies the data type of the elements, which can be any data type. |
predicate | Yes | A built-in function, user-defined function (UDF), or expression used to test each element. The input data type must match the element type T. |
Return value
Returns a BOOLEAN value:
trueif one or more elements satisfy the predicate.falseif no elements satisfy the predicate, or if the array is empty.nullif an element in the array isnulland other elements do not satisfy the predicate.
Examples
Example 1: At least one element satisfies the condition, so the function returns true.
-- Returns true. 100 satisfies x > 3.
SELECT any_match(array(1, 2, -10, 100, -30), x -> x > 3);Example 2: The array is empty, so the function returns false.
-- Returns false.
SELECT any_match(array(), x -> x > 3);Example 3: No elements satisfy the condition, so the function returns false.
-- Returns false. No element in the array is greater than 3.
SELECT any_match(array(1, 2, -10, -20, -30), x -> x > 3);Example 4: The array contains a null element, and no other element satisfies the condition, so the function returns null.
-- Returns null. The array contains null, and no non-null element satisfies x > 3.
SELECT any_match(array(1, 2, null, -10), x -> x > 3);Related functions
ANY_MATCH is a complex type function. For all functions that operate on complex data types such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.
The examples above use lambda expressions with the -> operator. For syntax details, see Lambda functions.