An aggregate function that returns true if any value in a Boolean column is true, and false if all values are false.
Syntax
BOOLEAN BOOL_OR(BOOLEAN <expr>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
expr | Yes | BOOLEAN | The Boolean expression to evaluate across all rows in a group. |
Return value
Returns a BOOLEAN value according to these rules:
Returns
trueif at least one value in the group istrue.Returns
falseif all values in the group arefalse.Ignores NULL values.
Examples
Example 1: Basic usage
SELECT BOOL_OR(colname)
FROM VALUES (true), (false), (false) AS tab(colname);Result: true — at least one row is true.
Example 2: NULL values are ignored
SELECT BOOL_OR(colname)
FROM VALUES (NULL), (true), (false) AS tab(colname);Result: true — the NULL row is excluded from evaluation.
SELECT BOOL_OR(colname1)
FROM VALUES (false), (false), (NULL) AS tab(colname1);Result: false — after excluding the NULL, all remaining values are false.
Example 3: Filter rows before aggregation with FILTER
FILTER(WHERE ...) restricts which rows participate in the aggregation without removing rows from the result set. This differs from WHERE, which filters rows before grouping and can drop entire groups from the output.
SELECT BOOL_OR(colname1) FILTER(WHERE colname2 = 1)
FROM VALUES (true, 1), (false, 1), (true, 2) AS tab(colname1, colname2);Result: true — only rows where colname2 = 1 are evaluated; the row (true, 2) is excluded from the aggregation.
Related functions
BOOL_AND: Returns
trueonly if all values in the group aretrue. Use this when you need "all rows satisfy a condition" semantics instead of "any row satisfies a condition."