BOOL_AND() OVER ...
All functions > WINDOW FUNCTION > BOOL_AND() OVER ...
Returns TRUE if all boolean values in the window frame are true.
Syntax
BOOL_AND(expr) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- Logical AND over all boolean values in the window
- Returns FALSE if any value is false
- NULL values are ignored
- Returns BOOLEAN type
See also
Examples
FeatureQL
SELECT
-- Running logical AND
f1 := ZIP(
ARRAY(1, 2, 3, 4) AS id,
ARRAY(30, 10, 20, 5) AS v,
ARRAY(TRUE, FALSE, TRUE, FALSE) AS b
).TRANSFORM(SELECT BOOL_AND(b) OVER (ORDER BY id ASC)).UNWRAP(),
-- Running AND counting only rows where v > 15 (10 and 5 excluded from the frame)
f2 := ZIP(
ARRAY(1, 2, 3, 4) AS id,
ARRAY(30, 10, 20, 5) AS v,
ARRAY(TRUE, FALSE, TRUE, FALSE) AS b
).TRANSFORM(SELECT BOOL_AND(b) FILTER (WHERE v > 15) OVER (ORDER BY id ASC)).UNWRAP()
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [true, false, false, false] | [true, true, true, true] |