How a write can handle a conflict in SQL
Ignore it, replace the row, or update the parts you meant to update.
INSERT OR IGNORE INTO tags (name)
VALUES ('sql');
INSERT OR REPLACE INTO daily_counts (day, hits)
VALUES ('2026-07-29', 1);
INSERT INTO daily_counts (day, hits)
VALUES ('2026-07-29', 1)
ON CONFLICT (day)
DO UPDATE SET
hits = daily_counts.hits + 1
WHERE daily_counts.hits < 1000;
How it works
INSERT OR IGNOREskips the row that would violate a constraint.INSERT OR REPLACEdeletes the old row first — including its other columns.ON CONFLICT DO UPDATEis the one that merges rather than clobbers.
Keywords and builtins used here
DOIGNOREINSERTINTOONORREPLACESETUPDATEVALUESWHEREday
The run, in numbers
- Lines
- 12
- Characters to type
- 280
- Tokens
- 66
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 42 seconds.
Step 4 of 5 in Transactions, step 14 of 17 in Plans & performance.