Updating Only the Version Previously Observed

A conditional update can require both the row identity and the previously observed version. This makes an intervening edit observable to the caller.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two editors
  2. Treat zero updated rows as a result
  3. Read the affected row count as evidence
  4. Verify the version update belongs to the same write

Trace two editors

Both read article 12 at version four. The first commits an update advancing it to five. The second's version-four update then matches no row. A target predicate describes the match.

Treat zero updated rows as a result

The caller can reload and resolve the conflict under the workflow. Test two copies of the old version. Optimistic concurrency control develops the broader validation model.[1]

Read the affected row count as evidence

Suppose a document at version four is edited by clients A and B. A saves with a predicate requiring version four and advances it to five. B's update with the old predicate then affects zero rows. Return a documented conflict outcome or reload and retry deliberately. See lost read–modify–write updates.

Before: version 4
A update where version=4 → one row, version becomes 5
B update where version=4 → no rows
B must not report the stale edit as saved

Verify the version update belongs to the same write

Updating content and version in independent operations can break the guarantee. Decide how to distinguish a deleted row from a version conflict if callers need both. Test that the first edit's text remains visible.

References

  1. PostgreSQL Global Development Group, Concurrency Control ↩