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"
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.
-- 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;For this error
See this error live on the server
Run these against the affected instance to confirm the diagnosis before you act.
New row violates exclusion constraint is explained by a stored integrity rule. Match the constraint name from PostgreSQL DETAIL to the catalog definition before changing data or code.
Exclusion constraints and operators
Map the named exclusion constraint to its indexed expressions/operators.
SELECT conname, conrelid::regclass AS table_name,
conindid::regclass AS backing_index,
pg_get_constraintdef(oid) AS definition
FROM pg_constraint
WHERE contype = 'x'
ORDER BY conrelid::regclass::text, conname;Why it happens
What PostgreSQL is telling you
The mechanism behind the error, grounded in the official manual, not paraphrased.
PostgreSQL 16 Documentation, §5.4.6 Exclusion Constraints
Exclusion constraints ensure that if any two rows are compared on the specified columns or expressions using the specified operators, at least one of these operator comparisons will return false or null.Read the full section on postgresql.org →
The insert that violates the exclusion constraint
10:30-11:30 overlaps 10:00-11:00, so the && comparison is true for both room_id and during, and the constraint rejects the row. The DETAIL line names the exact conflicting existing row.Checking the table afterward
Only the original reservation is in the table. The rejected overlapping insert was never stored.Reproduce & verify
A real, single-session PostgreSQL reproduction
A literal transcript of SQL run against a live PostgreSQL instance in an isolated lab. The commands below are exactly what was executed.
- 1Create a table with EXCLUDE USING gist to prevent overlapping ranges for the same key.
- 2Insert a row, then try to insert a second row for the same key with an overlapping range.
- 3PostgreSQL rejects the second row with SQLSTATE 23P01.
One client: create a room-booking table with an EXCLUDE constraint, insert one reservation, then try to insert an overlapping one for the same room.
CREATE SCHEMA IF NOT EXISTS booking;
CREATE EXTENSION IF NOT EXISTS btree_gist;
DROP TABLE IF EXISTS booking.reservations;
CREATE TABLE booking.reservations (
room_id integer,
during tsrange,
EXCLUDE USING gist (room_id WITH =, during WITH &&)
);
INSERT INTO booking.reservations (room_id, during) VALUES (1, '[2026-01-01 10:00, 2026-01-01 11:00)');-- same room, overlapping time range
INSERT INTO booking.reservations (room_id, during) VALUES (1, '[2026-01-01 10:30, 2026-01-01 11:30)');SELECT * FROM booking.reservations ORDER BY room_id, during;What PostgreSQL actually returned
NOTICE: extension "btree_gist" already exists, skipping
CREATE EXTENSION
DROP TABLE
CREATE TABLE
INSERT 0 1ERROR: conflicting key value violates exclusion constraint "reservations_room_id_during_excl"
DETAIL: Key (room_id, during)=(1, ["2026-01-01 10:30:00","2026-01-01 11:30:00")) conflicts with existing key (room_id, during)=(1, ["2026-01-01 10:00:00","2026-01-01 11:00:00")). room_id | during
---------+-----------------------------------------------
1 | ["2026-01-01 10:00:00","2026-01-01 11:00:00")
(1 row)The exclusion constraint was proven to allow exactly the cases it should: a genuinely different room, and a non-overlapping time range in the same room, back to back with no gap.
Without this
Above: an overlapping range for the same room is rejected.
With this, tested
Below: a different room, and a back-to-back non-overlapping range in the same room, are both accepted.
- A second operational test: exact SQL, raw output, measured result, and engineer notes
- Fix that looks equivalent but doesn't actually stop overlaps: exact SQL, output, and verdict
- A manual-grounded production interpretation of the lab result
Card required. Cancel before day 7 and you are not charged.
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.
Verification
- 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
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.