BOOL_AND
Returns true if a logical expression is true for all rows of the group.
PostgreSQL 17.5
BOOL_AND(expression)Parameters
- expressionboolean
- Logical expression or a boolean column
Return value
true, false or NULL
Examples
Were all born before 1990
PostgreSQL 17.5
SELECT status,
BOOL_AND(birthday < '1990-01-01') AS all_before_1990,
BOOL_OR(birthday < '1990-01-01') AS any_before_1990
FROM FamilyMembers
GROUP BY status
ORDER BY status;Do all rooms have internet
PostgreSQL 17.5
SELECT home_type,
BOOL_AND(has_internet) AS all_have_internet,
COUNT(*) AS rooms
FROM Rooms
GROUP BY home_type
ORDER BY home_type;Details
NULL values are ignored, and for an empty set the result is NULL. EVERY is the SQL-standard synonym for BOOL_AND. MIN and MAX do not work with boolean.