BOOL_OR

bool_or([distinct] expr)

Description

The BOOL_OR function is used to determine if there is a true value in a set of boolean values. When there is at least one true in the input dataset, the function returns true; if all values are false or null, it returns false. If the distinct parameter is not set, the function will calculate all values; after setting distinct, it will calculate the deduplicated values.

Parameter Description

  • expr (boolean type): The boolean expression that needs to be logically ORed.

Return Type

  • The return value type is boolean. When there is at least one true value, it returns true; otherwise, it returns false.
  • If all input data is null, it returns null.

Usage Example

  1. Returns true when there is at least one true value:
SELECT bool_or(col) FROM VALUES (true), (true), (null) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| true         |
+--------------+
  1. Returns false when all values are false or null:
SELECT bool_or(col) FROM VALUES (false), (false), (null) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| false        |
+--------------+
  1. Using the DISTINCT Parameter for Deduplication and Calculation:
SELECT bool_or(DISTINCT col) FROM VALUES (true), (true), (null) AS tab(col);
+-----------------------+
| bool_or(DISTINCT col) |
+-----------------------+
| true                  |
+-----------------------+
  1. Multiple false values and null values:
SELECT bool_or(col) FROM VALUES (false), (null), (null) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| false        |
+--------------+
  1. Mixed Values Situation:
SELECT bool_or(col) FROM VALUES (true), (false), (null), (true) AS tab(col);
+--------------+
| bool_or(col) |
+--------------+
| true         |
+--------------+