Aggregate Bitwise Or?

I see in the documentation that there is an aggregate bitwise xor function:
xor_agg(arg1: int) → int
Is there any way that I could do an aggregate bitwise or function?
Or is there any plans of adding such a thing in the future?

@ECourant There are no current plans for adding an aggregate bitwise-or function, but doing so wouldn’t be particularly difficult. Please file an issue requesting the feature and describing why you need it (the latter part helps us prioritize or possibly offer an alternative).

It’s not a huge need, was just wondering if there was a simple or existing way to do it in SQL rather than in the application itself. But thank you very much.

Dear Elliot,

thank you for your interest in CockroachDB.

You can readily implement boolean OR aggregations using sum(), because they are equivalent to addition over the set of two boolean values. To achieve this you simply need to cast back and forth to integers. For example:

select sum(boolcol::int)::bool from sometable;

Unfortunately at this time CockroachDB does not provide a product() aggregation so the corresponding AND aggregation is not directly available. As Peter said it might be a matter of filing the appropriate issue.

Hope this helps

We already have BOOL_OR (and BOOL_AND); the question was for a bitwise OR though. Postgres has BIT_AND and BIT_OR (and doesn’t have XOR as far as I can tell); we should probably add them too.

Note that XOR_AGG was added for an internal purpose (which explains why we have that but not AND/OR).