transaction
Write skew
Two transactions read the same invariant and update disjoint rows, each relying on stale assumptions. Snapshot isolation alone may allow both commits. Target: PostgreSQL 17. Example is a connection-specific schedule, not a single executable script.
Formal Syntax & Structure
sql syntaxsql
BEGIN ISOLATION LEVEL REPEATABLE READWorking Example
Example Snippetsql
-- Fresh fixture: CREATE TABLE t(id INT PRIMARY KEY, n INT NOT NULL);-- INSERT INTO t VALUES (1,10),(2,10);-- Use two independent connections A and B; setup committed first.-- A: BEGIN ISOLATION LEVEL REPEATABLE READ;-- B: BEGIN ISOLATION LEVEL REPEATABLE READ;-- A: SELECT SUM(n) FROM t;-- B: SELECT SUM(n) FROM t;-- A: UPDATE t SET n=0 WHERE id=1;-- B: UPDATE t SET n=0 WHERE id=2;-- A: COMMIT;-- B: COMMIT;-- A: SELECT SUM(n) FROM t;-- Roll back any open transactions after observation.