BOOL_AND
bool_and([distinct] expr)
Description
The BOOL_AND function is used to determine whether a set of boolean values (expr) are all true. When all given boolean values are true, the function returns true; otherwise, it returns false. If the distinct keyword is set, the function will only evaluate unique boolean values.
Parameter Description
- expr: The boolean expression to be logically ANDed.
Return Type
Boolean value.
Usage Example
- Determine if all boolean values are true:
SELECT bool_and(col) FROM VALUES (true), (true), (true) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| true |
+---------------+
- Cases with null values:
SELECT bool_and(col) FROM VALUES (true), (true), (null) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| true |
+---------------+
- Use the distinct keyword to determine if all boolean values are true after deduplication:
SELECT bool_and(DISTINCT col) FROM VALUES (true), (true), (true) AS tab(col);
+------------------------+
| bool_and(DISTINCT col) |
+------------------------+
| true |
+------------------------+
- Cases that include false values:
SELECT bool_and(col) FROM VALUES (false), (true), (null) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| false |
+---------------+
- Only contains one true value and one false value:
SELECT bool_and(col) FROM VALUES (true), (false) AS tab(col);
+---------------+
| bool_and(col) |
+---------------+
| false |
+---------------+