Performs a logical AND operation on a set of Boolean values and returns the Boolean result.
Syntax
BOOLEAN BOOL_AND(BOOLEAN <expr>)Parameters
expr: Required. A Boolean expression.
Return value
A value of the Boolean type is returned. The return value follows these rules:
If all values in the input expr are true, true is returned. Otherwise, false is returned.
If the input expr contains NULL values, the NULL values are excluded from the calculation.
Examples
Example 1: Perform a simple logical AND operation.
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: When NULL values exist in the array, they are ignored in the group.
SELECT BOOL_AND(colname) FROM VALUES (NULL), (true), (true) AS tab(colname); -- Result +------+ | _c0 | +------+ | true | +------+Example 3: Calculate the logical AND result of all rows in the colname1 column where colname2=1.
SELECT BOOL_AND(colname1) FILTER(WHERE colname2 = 1) FROM VALUES (true, 1), (false, 2), (true, 1) AS tab(colname1, colname2); -- Result +------+ | _c0 | +------+ | true | +------+