All Products
Search
Document Center

MaxCompute:BOOL_AND

Last Updated:Mar 26, 2026

Performs a logical AND operation across a set of Boolean values and returns a single Boolean result.

Syntax

BOOLEAN BOOL_AND(BOOLEAN <expr>)

Parameters

Parameter Required Type Description
expr Yes BOOLEAN A Boolean expression to aggregate.

Return value

Returns a value of type BOOLEAN.

  • Returns true if all non-NULL values in expr are true; otherwise returns false.

  • NULL values are excluded from the calculation.

Usage notes

  • Use a FILTER(WHERE ...) clause to restrict aggregation to a subset of rows without filtering the input table.

Examples

Example 1: Aggregate with mixed true and false values

When at least one value is false, BOOL_AND returns false.

SELECT BOOL_AND(colname) FROM VALUES (true), (false), (true) AS tab(colname);

Result:

+-------+
| _c0   |
+-------+
| false |
+-------+
SELECT BOOL_AND(colname1) FROM VALUES (true, 1), (false, 2), (true, 1) AS tab(colname1, colname2);

Result:

+-------+
| _c0   |
+-------+
| false |
+-------+

Example 2: NULL values are ignored

NULL rows are excluded from the aggregation. Only non-NULL values determine the result.

SELECT BOOL_AND(colname) FROM VALUES (NULL), (true), (true) AS tab(colname);

Result:

+------+
| _c0  |
+------+
| true |
+------+

Example 3: Filter rows before aggregating

Use FILTER(WHERE ...) to aggregate only the rows that match a condition.

SELECT BOOL_AND(colname1) FILTER(WHERE colname2 = 1)
FROM VALUES (true, 1), (false, 2), (true, 1) AS tab(colname1, colname2);

This query aggregates only the rows where colname2 = 1 — that is, (true, 1) and (true, 1) — and ignores (false, 2). The result is true.

+------+
| _c0  |
+------+
| true |
+------+