SQLSTATE 23P01Severity lowLab verified

Incident brief

New row violates exclusion constraint

A table has an EXCLUDE constraint, and a new row conflicts with an existing row under the constraint's comparison, most commonly, two overlapping time ranges for the same resource.

What lands in your log

ERROR: conflicting key value violates exclusion constraint "reservations_room_id_during_excl"

Reproduced on PostgreSQL 16.14Verified 2026-07-15 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
Create a table with EXCLUDE USING gist to prevent overlapping ranges for the same key.
Fix
Pick a range that does not overlap an existing one for the same key.
Proof
Reproduced on PostgreSQL 16.14 → The second reservation for room 1, overlapping the first by 30 minutes, was rejected with SQLSTATE 23P01 and only the original reservation remained.

Fix

What to do right now

Application-level steps for this error.

  • Pick a range that does not overlap an existing one for the same key.
  • Query for conflicts (using the && operator) before inserting, if the application needs a friendlier error than a constraint violation.
  • Use EXCLUDE, not a plain UNIQUE constraint, whenever the rule is about overlap rather than exact duplicates.
Fix SQL
-- Non-overlapping range for the same room is accepted (table already exists).
INSERT INTO booking.reservations (room_id, during)
  VALUES (1, '[2026-01-01 11:00, 2026-01-01 12:00)');
SELECT room_id, during FROM booking.reservations ORDER BY during;

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-07-15 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops