0

From here: https://stackoverflow.com/a/27868682/10894456

SELECT ... FOR UPDATE will lock the record with a write (exclusive) lock until the transaction is completed (committed or rolled back).

To select a record and ensure that it's not modified until you update it, you can start a transaction, select the record using SELECT ... FOR UPDATE, do some quick processing, update the record, then commit (or roll back) the transaction.

and here https://stackoverflow.com/a/5411366/10894456

note that FOR UPDATE outside of a transaction is meaningless

So since INSERT FOR UPDATE is meaningless without a transaction & transactions use locks by itself, what is the usecase of INSERT FOR UPDATE? My only guess: SELECT ... FOR UPDATE makes sense only if transaction has a low isolation level ( like read_uncommit), but I'm not sure, help me please

J.J. Beam
  • 2,612
  • 2
  • 26
  • 55

1 Answers1

0

Found here: https://stackoverflow.com/a/16963718/10894456

The main difference between SERIALIZABLE and using SELECT FOR UPDATE is that with SERIALIZABLE everything is always locked. Where as with SELECT FOR UPDATE you get to choose what and when you lock.

So SELECT FOR UPDATE allows us to be picky

J.J. Beam
  • 2,612
  • 2
  • 26
  • 55