Hackers,
Currently, `bytea` does not have any bitwise logical operations yet.
This issue came up in an old thread from 2006 [1], but nobody seemed to
have picked this issue so far.
Being in the need for this myself, I copied the bit vector's bitwise
logical operations and converted them to bytea. I'm using this as a
PostgreSQL extension right now, but would be very happy to see this
integrated into mainstream as default bytea operations in the future.
Find attached the implementation, plus a SQL file, for:
* bytea_xor
* bytea_and
* bytea_or
* bytea_not
* bytea_bitsset (returns number of set bits in a bytea; feel free to
drop this one if you don't see utility)
Tested on PG 9.6. I hope you find this useful.
Cheers,
Christian
[1]: https://www.postgresql.org/message-id/5171.1146927915%40sss.pgh.pa.us