DBAtlas · Database operations atlas

23P01: exclusion_violation

PostgreSQL

What does it mean?

An EXCLUDE (exclusion) constraint was violated. This constraint type prevents two rows from conflicting according to specific operators (e.g. range overlap &&); the inserted/updated row was rejected because it conflicts with an existing row.

Why does it happen?

Typically a GiST-based EXCLUDE constraint is defined (e.g. forbidding time overlaps with tstzrange && for appointment/room bookings) and the new row has a range/value that overlaps an existing row. Can also occur when two concurrent transactions insert overlapping ranges.

How to fix it

Check for the overlap with a query before inserting, or catch the error in the application and show the user a meaningful message. Query the relevant range/condition to find the conflicting existing row. If the business rule allows overlaps, relax the constraint; otherwise correct the input. Under concurrency, retry the transaction safely to serialize it.

Open in DBAtlas →

More from this engine