transaction

Phantom read

Repeating a predicate query can expose new matching rows under read committed. PostgreSQL repeatable read prevents this phenomenon. Target: PostgreSQL 17. Example is a connection-specific schedule, not a single executable script.

Formal Syntax & Structure

sql syntaxsql
SELECT ... WHERE ... (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 ISOLATION LEVEL READ COMMITTED;-- A: SELECT COUNT(*) FROM t WHERE n>0;-- B: INSERT INTO t VALUES(3,10);-- A: SELECT COUNT(*) FROM t WHERE n>0;-- Roll back any open transactions after observation.
SQL Reference