bytea bitwise logical operations implementation (xor / and / or /not) - Mailing list pgsql-hackers

From Christian Rossow
Subject bytea bitwise logical operations implementation (xor / and / or /not)
Date
Msg-id 74a3f8f0-d1d4-1d6e-dd81-fb2cf89ef88f@gmail.com
Whole thread Raw
Responses Re: bytea bitwise logical operations implementation (xor / and / or/ not)
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [HACKERS] Proposal: Local indexes for partitioned table
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] [PATCH] Generic type subscripting