transaction
Deadlock
A cycle of incompatible lock waits can cause deadlock. PostgreSQL aborts a participant (40P01); consistent acquisition order reduces risk. Retry the entire affected transaction if appropriate. Target: PostgreSQL 17. Example is a connection-specific schedule, not a single executable script.
Formal Syntax & Structure
sql syntaxsql
UPDATE ... (concept)Working 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;-- B: BEGIN;-- A: UPDATE t SET n=1 WHERE id=1;-- B: UPDATE t SET n=2 WHERE id=2;-- A async: UPDATE t SET n=1 WHERE id=2;-- B async: UPDATE t SET n=2 WHERE id=1;-- Roll back any open transactions after observation.