could not create exclusion constraint “…”

SQLSTATE 23P01 condition exclusion_violation class 23 — Integrity Constraint Violation severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 9 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

A statement failed with SQLSTATE 23P01 (exclusion_violation), reported at severity ERROR. This is a Integrity Constraint Violation condition: PostgreSQL emits the message could not create exclusion constraint "…".

What the server log shows

ERROR:  could not create exclusion constraint "…"
DETAIL:  Key … conflicts with key ….

Why PostgreSQL raises this

Class 23 (Integrity Constraint Violation) is raised when a write would break a declared constraint — NOT NULL, CHECK, UNIQUE/primary key, foreign key, or exclusion.

As described in PostgreSQL’s Section 5.4 Constraints and Appendix A (PostgreSQL Error Codes), SQLSTATE 23P01 carries the condition name exclusion_violation in class Integrity Constraint Violation. (Paraphrased — see the linked reference for the exact wording.)

Common causes

How to fix it

  1. Identify the offending row and reconcile it with the constraint.
  2. Insert or fix the referenced parent row before the child.
  3. Use ON CONFLICT to handle duplicates intentionally.
  4. Review the constraint definition to confirm it matches the data model.

Version applicability

This message is present in PostgreSQL 15, 16, 17, 18 and 19.

Related & next steps

Reference: PostgreSQL Section 5.4 Constraints.