5 ms·
It kinda depends. I might do it like this if its super simple: UPDATE A, B SET A.x = B.x where A.b_id = B.id and A.id = 1; If it's more complex, it might hav
by bcrosby95 3y ago
It kinda depends. I might do it like this if its super simple:
UPDATE A, B SET A.x = B.x where A.b_id = B.id and A.id = 1;
If it's more complex, it might have to be more like this:
SELECT * FROM A ... FOR UPDATE;
SELECT * FROM B... FOR SHARE;
UPDATE A...
If B is only ever updated after locking A, you can safely do this:
SELECT * FROM A ... FOR UPDATE;
SELECT * FROM B...;
UPDATE A...
Generally speaking, I wouldn't recommend locking "for share" then updating it later. This can result in deadlocks because you're upgrading it to an exclusive lock.