Predict the output
Two replicas try to claim tonight's billing run. What does the final SELECT print?
CREATE TABLE runs (period date PRIMARY KEY, status text);
INSERT INTO runs VALUES ('2026-10-31', 'running')
ON CONFLICT DO NOTHING;
INSERT INTO runs VALUES ('2026-10-31', 'running')
ON CONFLICT DO NOTHING;
SELECT count(*) FROM runs;Hint 1 of 1
What's the primary key?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 1
Correct. The second claim conflicts and does nothing, so only one replica runs it.
The primary key on period makes 'claim this run' a single atomic insert. Whichever replica inserts first wins, and the other's insert does nothing, so one row exists.
Why not the others?
- B
2. The primary key on period rejects the second row. - C A unique violation. ON CONFLICT DO NOTHING absorbs it.
- D
0. The first insert succeeds.
| count |
|---|
| 1 |
(1 row)