BeginnersSake
BeginnersSake

Reputation: 680

Setting a bit of bytea column using Postgresql

I have a table which has a column of type bytea. I want to update it and set 76th bit as 1. What query should I use ?

Upvotes: 1

Views: 390

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246073

To change the 42nd bit to 1, you could use

UPDATE tab
SET binval = set_bit(binval, 41, 1)
WHERE ...

Note that you may be faster with such operations (but waste space) if you change the column to EXTERNAL instead of EXTENDED storage (see the TOAST documentation).

Upvotes: 2

Related Questions