Link Search Menu Expand Document

ALL_MATCH

Returns 1 (true) when the Boolean expression <Boolean_expr> performed on all elements of an array evaluate to true. Returns 0 (false) when any one comparison evaluates to false.

Syntax

ALL_MATCH(<array_var> -> <Boolean_expr>, <array_expr>)
Parameter Description
<array_var> A Lambda array variable that contains elements of the array specified using <array_expr>. For more information, see Manipulating arrays with Lambda functions.
<Boolean_expr> A Boolean expression that evaluates each array value using a comparison operator. For available operators, see Comparison operators.
<array_expr> An expression that evaluates to an ARRAY data type.

Examples

Return 1 (true) if all elements in the array are greater than 0.

SELECT
	ALL_MATCH(x -> x > 0, [ 1, 2, 3, 9 ]) AS comparisons_result;

Returns:

+--------------------+
| comparisons_result |
+--------------------+
| 1                  |
+--------------------+

Return 1 (true) if gadgets does not appear in the array.

SELECT
	ALL_MATCH(x -> x <> 'gadgets', [ 'audio', summer-sale', 'gadgets']) AS comparisons_result;

Returns:

+--------------------+
| comparisons_result |
+--------------------+
| 0                  |
+--------------------+