Search code examples
sqlpostgresqllockingselect-for-update

Postgres SELECT .. FOR UPDATE and WHERE clause order


I am trying to select some with lock and use select for update with where clause. Should I check in my service that this where actually worked? I mean, is this right order?

  • Raw is selected using where clause
  • Waiting for lock (in another transaction raw changed and where clause is wrong now)
  • Acquire lock and return rows

And how can I check this behaviour?


Solution

  • The query is guaranteed to return only rows that satisfy the WHERE condition.