Returns true if any element in the array matches the given condition, false otherwise. If the array contains NULL elements and all non-NULL elements are false, returns NULL.
array_match_any(lambda, <arr> [, <arr> ...])
lambda: A lambda expression that defines the condition to check for each element<arr>: One or more arrays to check. The lambda function will be applied to each element of these arraysReturns a nullable boolean value:
true if any element in the array matches the conditionfalse if all elements in the array do not match the conditionNULL if the array contains NULL elements and all non-NULL elements do not match the condition-- Check if any number in array is greater than 5 mysql> SELECT array_match_any(x -> x > 5, [1, 2, 3, 4, 7]); +----------------------------------------------+ | array_match_any(x -> x > 5, [1, 2, 3, 4, 7]) | +----------------------------------------------+ | 1 | +----------------------------------------------+ -- Check if any number in array is greater than corresponding numbers in another array mysql> SELECT array_match_any((x, i) -> x > i, [1, 2, 3, 4, 5], [1, 2, 3, 4, 7]); +--------------------------------------------------------------------+ | array_match_any((x, i) -> x > i, [1, 2, 3, 4, 5], [1, 2, 3, 4, 7]) | +--------------------------------------------------------------------+ | 0 | +--------------------------------------------------------------------+ mysql> SELECT array_match_any((x, i) -> i > x, [1, 2, 3, 4, 5], [1, 2, 3, 4, 7]); +--------------------------------------------------------------------+ | array_match_any((x, i) -> i > x, [1, 2, 3, 4, 5], [1, 2, 3, 4, 7]) | +--------------------------------------------------------------------+ | 1 | +--------------------------------------------------------------------+
The function handles NULL values in the following way:
This function is useful for: