23P01
Read PG 18 manual ↗exclusion_violation
- SQLSTATE
- 23P01
- Condition name
- exclusion_violation
- Class
- Integrity Constraint Violation
- Source macro
- ERRCODE_EXCLUSION_VIOLATION
- Evidence
- Observed at runtime in the source evidence
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
23P01 means an exclusion constraint found an existing row for which all configured comparison operators conflict. The selected range case uses &&, so it rejects an overlap rather than merely a duplicate value.
Meaning
An exclusion constraint combines an index access method with operators such as range overlap. In the case registry, [5,12) conflicts with [1,10), while [10,12) is accepted because PostgreSQL’s half-open ranges do not overlap at 10. Operator classes and the configured operator combination determine the result; DEFERRABLE changes when the conflict is checked.
Diagnosis
Capture constraint_name, the key values in DETAIL, and whether the constraint is immediate or deferred. Inspect the existing rows with the same operator semantics; equality checks alone are insufficient. An immediate conflict is raised at the statement boundary, while a DEFERRABLE conflict can surface at SET CONSTRAINTS or COMMIT. The selected case is immediate and runs in autocommit mode, so its connection returns IDLE after the rejected insert.
Response
Choose a non-conflicting value or coordinate the conflicting booking/resource under the application’s concurrency policy. In autocommit, a failed statement ends its own transaction boundary and the connection can be reused. In an explicit transaction, an immediate error can leave the transaction aborted just as a deferred error can; issue ROLLBACK, or ROLLBACK TO SAVEPOINT when the operation was deliberately isolated in a savepoint, before retrying the complete operation. A DEFERRABLE conflict may be reported at SET CONSTRAINTS or COMMIT, so retry from the clean boundary required by that check point; retry only when the operation is safe and the conflict can actually resolve. Do not “fix” an overlap by changing range bounds without applying the business rule.
Observed diagnostics
18.6 (Homebrew) / latest:SQLSTATE 23P01; primary conflicting key value violates exclusion constraint "bookings_no_overlap"; DETAIL Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).; status_after_error IDLE.
10.21 (Debian 10.21-1.pgdg90+1) / pg10:SQLSTATE 23P01; primary conflicting key value violates exclusion constraint "bookings_no_overlap"; DETAIL Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).; status_after_error IDLE.
Representative case
In this example, the second booking overlaps the existing range and is repaired by moving its lower bound to the existing upper bound. The complete setup, assertions, and cleanup are in the case export:
-- create
CREATE TABLE bookings(id integer PRIMARY KEY, during int4range NOT NULL, CONSTRAINT bookings_no_overlap EXCLUDE USING gist (during WITH &&));
-- seed
INSERT INTO bookings VALUES (1, int4range(1, 10));
-- trigger
INSERT INTO bookings VALUES (2, int4range(5, 12));
-- repair
INSERT INTO bookings VALUES (2, int4range(10, 12));
-- verify
SELECT id, during::text FROM bookings ORDER BY id;
The SQLSTATE, diagnostic, transaction-state, and repair assertions for this excerpt are produced from the checked case registry; see the structured evidence and case export.
Authored evidence IDs: identity, mechanism, runtime. Selected runtime records: runtime.23P01-batch1-latest-20260909.latest, runtime.23P01-batch1-pg10-20260909.pg10.
Versions
The locked catalogue observes 23P01 from the 9.0.0 boundary and in every listed formal snapshot. The selected immediate range case passes on 18.6 and 10.21; it does not test deferred or concurrent exclusion checks.
Sources
src.errcodes.18.6(SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)src.calls.REL_18_6(SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)src.execIndexing.18.6(SHA-25624c80553ab4b28d7d2a288dd9196c8db9459c7f308853cd8c8c939485e15f199)doc.rangetypes.18.6(SHA-256cfeffb134d2acc2ec45141726583b041410665c4a2f8ecf66cd3f9484a7f0014) · official documentation
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
23P01 is exclusion_violation in Class 23.
Method: Read the fixed errcodes row.
Limits: The exclusion operator may compare more than equality; the operator class and constraint definition determine the conflict.
An exclusion constraint rejects a row when the configured operator comparisons are all true against an existing row; the range example uses && for overlap.
Method: Trace check_exclusion_or_unique_constraint and the range exclusion documentation.
Limits: A half-open range [10,12) does not overlap [1,10); changing bounds is a business rule, not a blanket retry.
src.execIndexing.18.6 doc.rangetypes.18.6 src.calls.REL_18_6
The selected immediate GiST range case returned 23P01 on PG18.6 and PG10.21, identified bookings_no_overlap, stayed IDLE, and committed a non-overlapping [10,12) range.
Method: Read the selected summaries and raw diagnostics.
Limits: This case does not test DEFERRABLE exclusion constraints, concurrent waits, or every operator class.
runtime.23P01-batch1-latest-20260909.latest runtime.23P01-batch1-pg10-20260909.pg10
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·- src/backend/executor/execIndexing.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - doc/src/sgml/rangetypes.sgml · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · conflict
Primary
conflicting key value violates exclusion constraint "%s"
Detail
Key %s conflicts with existing key %s.
The detail is dynamically built from the conflicting key values; the fallback is “Key conflicts with existing key.”
Reproduction & repair cases
overlapping_range_exclusion · PG 10, 18
Preconditions
- A range column has a GiST exclusion constraint using &&
- The second range overlaps the committed first range
Trigger: Insert an overlapping range.
Expected assertions
- SQLSTATE is 23P01
- The exclusion constraint is identified
- A non-overlapping range can be inserted afterward
Repair: Choose a non-overlapping interval or resolve the conflicting reservation according to business rules; do not treat exclusion as a generic duplicate-key check.
Cleanup: Drop the case schema with an owner connection.
Recorded runtime evidence
18.6 (Homebrew) · passed
Run: 23P01-batch1-latest-20260909
{
"rows": [
[
1,
"[1,10)"
],
[
2,
"[10,12)"
]
],
"detail": "Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).",
"primary": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"",
"sqlstate": "23P01",
"constraint": "bookings_no_overlap",
"status_after_error": "IDLE"
}10.21 (Debian 10.21-1.pgdg90+1) · passed
Run: 23P01-batch1-pg10-20260909
{
"rows": [
[
1,
"[1,10)"
],
[
2,
"[10,12)"
]
],
"detail": "Key (during)=([5,12)) conflicts with existing key (during)=([1,10)).",
"primary": "conflicting key value violates exclusion constraint \"bookings_no_overlap\"",
"sqlstate": "23P01",
"constraint": "bookings_no_overlap",
"status_after_error": "IDLE"
}Definition snapshot: english-manuals:59fae57a3e5d0b42a79a9c3958a… · English manual source