SQLSTATE 23P01 ERROR Class 23: Integrity Constraint Violation

exclusion_violation Exclusion Violation — SQLSTATE 23P01

A row conflicts with an EXCLUDE constraint.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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:

  1. Adjust the values so they no longer overlap any existing row.
  2. Catch the violation and present a conflict to the user.
  3. Inspect the constraint with pg_get_constraintdef to see the operator and columns.

Reference: PostgreSQL error codes — Class 23 (Integrity Constraint Violation).

Was this helpful?