Function Reference

BOOL_OR

Returns true if a logical expression is true for at least one row of the group.

PostgreSQL 17.5
BOOL_OR(expression)

Parameters

expressionboolean
Logical expression or a boolean column

Return value

true, false or NULL

Examples

NULL among the values

PostgreSQL 17.5
SELECT BOOL_AND(x) AS all_true,
	BOOL_OR(x) AS any_true
FROM (
		VALUES (TRUE),
			(NULL),
			(false)
	) AS t(x);
all_trueany_true
falsetrue

Does at least one room have a TV

PostgreSQL 17.5
SELECT home_type,
	BOOL_OR(has_tv) AS some_have_tv,
	COUNT(*) AS rooms
FROM Rooms
GROUP BY home_type
ORDER BY home_type;
home_typesome_have_tvrooms
Entire home/apttrue21
Private roomtrue28
Shared roomtrue1

Details

NULL values are ignored, and for an empty set the result is NULL. The same answer is given by COUNT(*) FILTER (WHERE ...) > 0, but BOOL_OR is shorter.

See also