I have a table which is
event_id BIGINT NOT NULL,
data BYTEA
and a column in this table is
event_id | data
----------+--------------------
2 | \x0000000000000000
Now, I want to update a slice of data like
UPDATE "bin_data" SET "data"=SET_BYTE("data", 0, 1) where "event_id"=2;
But, I'm not sure this option can concurrently or not.
If those two options
UPDATE "bin_data" SET "data"=SET_BYTE("data", 0, 1) where "event_id"=2;
UPDATE "bin_data" SET "data"=SET_BYTE("data", 1, 1) where "event_id"=2;
are executed parallelly.
In my test, the result is \x0101000000000000
, but I can't guarantee that my test is absolute parallelly.
I have an idea of how to solve it which is lock the row like this
UPDATE "bin_data" SET "data"=SET_BYTE((SELECT "data" FROM "data" WHERE "event_id"=2 FOR UPDATE), 0, 1) where "event_id"=2;
Is there any way to update a slice of bytea field parallelly without lock the row?