PostgreSQL: conflicting key value violates exclusion constraint
ERROR: conflicting key value violates exclusion constraint "<constraint>"A row conflicts with an existing one under an exclusion constraint, typically overlapping ranges such as a double-booked time slot. Adjust the value so it no longer overlaps, or serialize the conflicting writes.
What this error means
An exclusion constraint (EXCLUDE USING gist) enforces that no two rows conflict on a given expression, most often that ranges do not overlap. When a write would create an overlap, Postgres rejects it.
It is common in scheduling and booking systems using range types like tstzrange.
How to fix it
The new range overlaps an existing one
Change the value so it does not overlap, for example by choosing a free time slot.
Concurrent writers race for the same slot
Serialize the conflicting writes, or catch the error and retry with a different slot.
How to avoid it next time
- Check availability before writing, but rely on the constraint as the source of truth.
- Design ranges and the exclusion operator to match how bookings must not overlap.
Frequently asked questions
What is an exclusion constraint?
A constraint that forbids rows from conflicting on an expression, commonly used with range types to prevent overlapping bookings.
How is it different from a unique violation?
Unique forbids equal values. Exclusion forbids conflicting values under an operator, such as overlapping ranges, which is more general.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.