I have about 10 queries that concurrently update a row, so I want to know what is the difference between
UPDATE account SET balance = balance + 1000
WHERE id = (SELECT id FROM account
where id = 1 FOR UPDATE);
and
BEGIN;
SELECT balance FROM account WHERE id = 1 FOR UPDATE;
-- compute $newval = $balance + 1000
UPDATE account SET balance = $newval WHERE id = 1;
COMMIT;
I am using PosgreSQL 11, so what is the right solution and what will happen with multi transactions in these two solutions?