Usage with a FOR UPDATE
Clause
If the FOR UPDATE
sub-clause precedes the WITH LOCK
sub-clause, buffered fetches are suppressed.Thus, the lock will be applied to each row, one by one, at the moment it is fetched.It becomes possible, then, that a lock which appeared to succeed when requested will nevertheless fail subsequently, when an attempt is made to fetch a row which has become locked by another transaction in the meantime.This can be avoided by also using SKIP LOCKED
.
Tip
|
As an alternative, it may be possible in your access components to set the size of the fetch buffer to 1.This would enable you to process the currently-locked row before the next is fetched and locked, or to handle errors without rolling back your transaction. |