Symptoms
A row conflicts with an EXCLUDE constraint.
- The error is written to the server log and returned to the client carrying
SQLSTATE 23P01. - Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
- PL/pgSQL can trap it by name:
EXCEPTION WHEN exclusion_violation THEN.
Environment
Severity: ERROR | PostgreSQL versions: 12, 13, 14, 15, 16, 17
Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).
Root Cause
The new row overlaps an existing one according to an exclusion constraint — commonly overlapping ranges or geometries using the && operator.
Common causes:
- Overlapping time ranges (double-booking).
- Overlapping spatial regions.
Diagnostic Queries
Recovery
Steps to resolve 23P01:
- Adjust the values so they no longer overlap any existing row.
- Catch the violation and present a conflict to the user.
- Inspect the constraint with
pg_get_constraintdefto see the operator and columns.
Reference: PostgreSQL error codes — Class 23 (Integrity Constraint Violation).
Thanks — noted. This helps keep the database accurate.