ARRAY_ALL_MATCH
- Returns
TRUE
if all elements in the array areTRUE
or if the array is empty. - Returns
FALSE
if any element in the array isFALSE
. - Returns
NULL
if any element isNULL
and no element isFALSE
.
When an optional lambda function is provided, ARRAY_ALL_MATCH
applies the function to each element and then evaluates the resulting array.
Alias: ALL_MATCH
Syntax
{ ALL_MATCH | ARRAY_ALL_MATCH }([<expression> -> <condition>], <array> [, <array2>, ...])
Parameters
Parameter | Description | Supported input types |
---|---|---|
<expression> | A lambda function applied to each element of the input arrays, returning a BOOLEAN . If no lambda function is provided, the function can only evaluate a single BOOLEAN array. For more information, see Manipulating arrays with Lambda functions. | Same as the element data types of the input arrays. |
<condition> | A BOOLEAN expression that evaluates each array value using a comparison operator. | See Comparison operators. |
<array> | The array to evaluate. | ARRAY |
Return Type
The ARRAY_ALL_MATCH
function returns a result of type BOOLEAN
.
Examples
The following code example checks if all elements in the array end with '2024'
:
SELECT ARRAY_ALL_MATCH(name -> name like '%2024', [ 'kennethpark2024', 'sabrina2024', 'steven2024']) AS result;
Returns The previous code returns TRUE
because each name in the array matches the condition:
result (BOOLEAN) |
---|
t |
Example
The following code example checks if each element in the first array is divisible by the corresponding element in the second array, and returns TRUE
if all pairs satisfy the condition:
SELECT ARRAY_ALL_MATCH(x, y -> (x % y) = 0, [ 10, 20, 30, 45 ], [ 5, 10, 2, 15]) AS divisible;
Returns The previous code returns TRUE
because all pairs in the first array are divisible by its corresponding second array:
divisible (BOOLEAN) |
---|
t |
Example The following code example evaluates multiple arrays using ARRAY_ALL_MATCH
:
SELECT ARRAY_ALL_MATCH([]) as empty,
ARRAY_ALL_MATCH([true]) as single_true,
ARRAY_ALL_MATCH([false]) as single_false,
ARRAY_ALL_MATCH([NULL]) as single_null,
ARRAY_ALL_MATCH([false, NULL]) as false_and_null;
RETURNS The previous code returns TRUE
for an empty array, TRUE
for an array with TRUE
, FALSE
for any array with FALSE
, NULL
for an array with NULL
, and FALSE
for an array containing both FALSE
and NULL
:
empty (BOOLEAN) | single_true (BOOLEAN) | single_false (BOOLEAN) | single_null (BOOLEAN) | false_and_null (BOOLEAN) |
---|---|---|---|---|
t | t | f | NULL | f |