Reputation: 11
I need to perform a BITWISE_OR
on all grouped by values.
Say, my values in a group by are: 100, 010, and 110. And I need to calculate "100 or 010 or 110" which is 110.
So I want to do something like: select col1, array_agg(col2) from table group by col1
, then apply bitwise_or
on all col2 values in the array. There's a function bitwise_or_agg
, but it doesn't work on an array.
Any help is appreciated!
Upvotes: 1
Views: 385
Reputation: 38335
bitwise_or_agg(x)
is an aggregation function (Returns the bitwise “or” of all input values), use it instead of (or along with) array_agg:
select col1,
array_agg(col2) as my_array,
bitwise_or_agg(col2) as my_array_bitwise_or
from table group by col1
Upvotes: 1