Given that I have a table like this
ID X
1 TRUE
1 FALSE
2 FALSE
2 FALSE
I would like to achieve the following result:
ID BOOL_OR(X)
1 TRUE
2 FALSE
That is , I want to GROUP BY ID
and aggregate the boolean values of X
using the boolean OR operator.
PostgreSQL has bool_or()
that I can use like this
with t1 as
(
select *
from (values (1, true)
, (1, false)
, (2, false)
, (2, false)) AS t1 (id, x)
)
select id, bool_or(x)
from t1
group by id;
-- results
ID BOOL_OR(X)
1 TRUE
2 FALSE
The same query in Snowflake SQL gives SQL compilation error: Invalid identifier BOOL_OR
, which is no surprise since the Snowflake documentation for Aggregate functions does not list BOOL_OR
.
So my question is there some other alternative way to get the same effects as PostgreSQL's bool_or
and bool_and
in Snowflake SQL?