Request a demo

BigQuery · Aggregate function

BigQuery LOGICAL_OR

LOGICAL_OR returns TRUE if a BOOL expression is TRUE for at least one row of a group and FALSE if every non-NULL row is FALSE. Use it for 'did anything fail' or 'did this session purchase'. NULLs are ignored; an empty or all-NULL group returns NULL.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

LOGICAL_OR is the aggregate form of OR: it answers 'is this true for any row?' per group. It returns TRUE if at least one row is TRUE, FALSE if all non-NULL rows are FALSE, and NULL when there are no rows or only NULLs. PostgreSQL calls it BOOL_OR and Snowflake BOOLOR_AGG; in BigQuery only LOGICAL_OR exists.

It is handy in HAVING to keep groups where something happened at least once, such as sessions that added to cart but never purchased: HAVING LOGICAL_OR(event_name = 'add_to_cart') AND NOT LOGICAL_OR(event_name = 'purchase'). COUNTIF(x) > 0 gives the same answer for non-NULL data.

NULLs are ignored, so LOGICAL_OR(failed) over FALSE, NULL returns FALSE even though one result is unknown. If unknown should count as a problem, test for it explicitly: LOGICAL_OR(failed IS NOT FALSE) is TRUE for both TRUE and NULL.

Syntax

LOGICAL_OR(expression [WHERE where_expression])

Arguments and return value

ArgumentDescription
expressionA BOOL expression. NULLs are ignored.
WHERE where_expressionOptional filter inside the call (Preview).

Returns: BOOL. NULL for an empty group or when every value is NULL.

Examples

Which steps did each session reach?

WITH events AS (
  SELECT 's1' AS session_id, 'view' AS event_name UNION ALL
  SELECT 's1', 'add_to_cart' UNION ALL
  SELECT 's1', 'purchase' UNION ALL
  SELECT 's2', 'view' UNION ALL
  SELECT 's2', 'add_to_cart' UNION ALL
  SELECT 's3', 'view'
)
SELECT
  session_id,
  LOGICAL_OR(event_name = 'add_to_cart') AS added_to_cart,
  LOGICAL_OR(event_name = 'purchase') AS purchased
FROM events
GROUP BY session_id
ORDER BY session_id;
Result
session_idadded_to_cartpurchased
s1truetrue
s2truefalse
s3falsefalse

Abandoned carts with HAVING

WITH events AS (
  SELECT 's1' AS session_id, 'add_to_cart' AS event_name UNION ALL
  SELECT 's1', 'purchase' UNION ALL
  SELECT 's2', 'view' UNION ALL
  SELECT 's2', 'add_to_cart' UNION ALL
  SELECT 's3', 'view'
)
SELECT session_id
FROM events
GROUP BY session_id
HAVING LOGICAL_OR(event_name = 'add_to_cart')
  AND NOT LOGICAL_OR(event_name = 'purchase');
Result
session_id
s2

Unknown results are ignored

WITH runs AS (
  SELECT 'orders_daily' AS pipeline, FALSE AS failed UNION ALL
  SELECT 'orders_daily', NULL UNION ALL
  SELECT 'users_sync', FALSE
)
SELECT
  pipeline,
  LOGICAL_OR(failed) AS any_failed,
  LOGICAL_OR(failed IS NOT FALSE) AS any_failed_or_unknown
FROM runs
GROUP BY pipeline
ORDER BY pipeline;
Result
pipelineany_failedany_failed_or_unknown
orders_dailyfalsetrue
users_syncfalsefalse

Common mistakes

  • Treating NULL as a problem by default. NULLs are ignored, so a run with an unknown result doesn't make LOGICAL_OR TRUE. Use failed IS NOT FALSE when unknown should count.
  • Expecting FALSE for no rows. An aggregate over zero rows returns NULL. Wrap it as IFNULL(LOGICAL_OR(x), FALSE) if the caller expects a BOOL.
  • Passing an integer flag. LOGICAL_OR(has_error) on an INT64 column fails with No matching signature for aggregate function LOGICAL_OR; write LOGICAL_OR(has_error = 1).
  • Using BOOL_OR or BOOLOR_AGG from PostgreSQL or Snowflake. BigQuery answers with Function not found.

FAQ

How do I check whether any row meets a condition in BigQuery?

Use LOGICAL_OR(condition) per group, or in HAVING to keep only matching groups. COUNTIF(condition) > 0 is an alternative that returns FALSE instead of NULL for an empty input.

What is the BigQuery equivalent of BOOL_OR?

LOGICAL_OR. It ignores NULLs and returns NULL for an empty input, like PostgreSQL's BOOL_OR.

What is the difference between LOGICAL_OR and MAX on a BOOL column?

For BOOL values they agree: MAX returns TRUE when any value is TRUE, because FALSE sorts before TRUE. LOGICAL_OR states the intent more clearly and only accepts BOOL input.

Errors you may hit

More aggregate functions

All BigQuery aggregate functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.