select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 40 · TRANSACTION ROLLBACK

transaction_integrity_constraint_violation

SQLSTATE
40002
Condition name
transaction_integrity_constraint_violation
Class
Transaction Rollback
Source macro
ERRCODE_T_R_INTEGRITY_CONSTRAINT_VIOLATION
Evidence
Definition only
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>40002 — transaction_integrity_constraint_violation</h1>

At a glance

40002 is a catalogue-defined transaction-integrity condition. No distinct PostgreSQL core 40002 call site was resolved in the fixed scan used for this batch, so no foreign-key, unique, or other concrete constraint error is relabeled as this umbrella code. Capture the actual SQLSTATE emitted by the operation.

Meaning

40002 names transaction integrity constraint violation in Class 40, but the fixed PostgreSQL core scan did not resolve a distinct 40002 call site. PostgreSQL's concrete integrity mechanisms normally report a specific Class 23 code, such as 23502, 23503, 23505, 23514, or 23P01.

Diagnosis

Read the actual SQLSTATE, constraint name, relation, column, and DETAIL from the error. If the server reports a concrete Class 23 code, diagnose that constraint and its transaction state; do not promote it to 40002 because the operation was transactional. This page has no selected natural runtime case or server-specific message template.

Response

Repair the concrete constraint violation and its transaction boundary, then verify the intended durable state. Do not add a generic retry or relabel a known 235xx/23P01 result as 40002; use this class definition only when a real component supplies that code and its own evidence.

Versions

The locked facts table records catalogue presence across the project snapshot range. The fixed source evidence is limited to the path stated below; no exact behavioral introduction or broader runtime coverage is inferred from the definition alone.

Sources

  • src.errcodes.18.6 (SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)
  • src.calls.REL_18_6 fixed call scan (SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

40002 is the transaction_integrity_constraint_violation condition in Class 40.

Method: Read the fixed errcodes.txt row and macro mapping.

Limits: This records the protocol definition and does not imply a natural PostgreSQL throw path.

src.errcodes.18.6

No distinct safe natural core runtime case for 40002 was selected from the fixed call scan.

Method: Review the fixed call scan for resolved 40002 call groups and reject artificial RAISE or relabeling.

Limits: This is a bounded source/definition result, not proof that every extension or injected fault cannot emit the code.

src.calls.REL_18_6

Message templates

No extracted message template is attached to this condition.

Reproduction & repair cases

transaction_integrity_boundary · PG 10, 18

Preconditions

  • A runner-owned disposable target is provisioned.

Trigger: No natural core 40002 path was resolved in the fixed scan, so no SQL trigger is fabricated.

Expected assertions

    Repair: Use the concrete SQLSTATE emitted by the actual operation and reconcile the transaction outcome before retrying.

    Cleanup: Drop the case schema with an owner connection.

    Recorded runtime evidence

    No runtime observation is attached to this entry.

    Definition snapshot: english-manuals:402289a8df149570733ef79a433… · English manual source