Does Postgresql apply the same type of locks on UPDATE with range condition and on UPDATE with in-set condition?

Posted on

Question :

Does Postgresql apply the same type of locks on UPDATE with a range condition and on UPDATE with in-set condition?

E.g. will the queries:

  1. UPDATE table WHERE id IN (1,2,3,4,5,6,7,8,9,10);
  2. UPDATE table WHERE id >= 1 AND id < 11;

Cause the same type of locks on table?

Answer :

Yes, both statements will take a UPDATE lock on all the modified rows.

See the documentation on row locks:

The FOR UPDATE lock mode is also acquired by any DELETE on a row, and also by an UPDATE that modifies the values on certain columns.

Leave a Reply

Your email address will not be published. Required fields are marked *