选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

文档 / SQL 状态码 / Class 40 事务回滚

40002 transaction_integrity_constraint_violation

事务完整性约束违规

ERROR 仅定义 参考 未实测

类别
Class 40 事务回滚
严重等级
ERROR
条件名
transaction_integrity_constraint_violation
宏名称
ERRCODE_T_R_INTEGRITY_CONSTRAINT_VIOLATION
启用版本
7.4
状态
活跃

版本覆盖

速览

40002 是目录定义的事务完整性条件。本批固定扫描没有解析出独立的 PostgreSQL 核心 40002 抛出点,因此不把外键、唯一性或其他具体约束错误重新标成这个总括码。应保存操作实际发出的 SQLSTATE。

含义

40002 表示 40 类的事务完整性约束违规,但固定的 PostgreSQL 核心扫描没有解析出独立的 40002 调用点。PostgreSQL 的具体完整性机制通常报告 23 类具体码,例如 2350223503235052351423P01

诊断

从错误中读取实际 SQLSTATE、约束名、关系、列和 DETAIL。服务器给出具体 23 类码时,应按该约束及事务状态诊断;不能因为操作发生在事务中就升级为 40002。本页没有选定的自然运行案例,也没有服务器特定报文模板。

处理

修复具体约束违规和事务边界,再核对预期持久化状态。不要添加通用重试,也不要把已知 235xx/23P01 结果改称 40002;只有真实组件提供该码及其证据时才使用这一类定义。

可复现案例

在一次性实例上执行过的场景。

transaction_integrity_boundary PG 10 / 18

前置条件

  • A runner-owned disposable target is provisioned.

触发

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

处置

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

清理

Drop the case schema with an owner connection.

版本

上面的锁定事实表记录项目快照范围内的目录存在情况。固定源码证据只覆盖下面声明的路径;不能仅从定义推导精确行为引入版本或更广的运行覆盖。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 40002 is the transaction_integrity_constraint_violation condition in Class 40.

    核实方式Read the fixed errcodes.txt row and macro mapping.

    不覆盖This records the protocol definition and does not imply a natural PostgreSQL throw path.

    来源src/backend/utils/errcodes.txt

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

    核实方式Review the fixed call scan for resolved 40002 call groups and reject artificial RAISE or relabeling.

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

    来源raw/calls/REL_18_6.jsonl

同类 SQL 状态码

状态码 条件名 宏名称 严重等级 版本
Class 40 事务回滚 Transaction Rollback 5 个
40000 transaction_rollback ERRCODE_TRANSACTION_ROLLBACK ERROR 7.4
事务回滚的类别码,具体原因见 40001 等子码。 活跃
40001 serialization_failure ERRCODE_T_R_SERIALIZATION_FAILURE ERROR 7.4
并发事务无法串行化,需回滚后重试。 活跃
40002 transaction_integrity_constraint_violation ERRCODE_T_R_INTEGRITY_CONSTRAINT_VIOLATION ERROR 7.4
事务级完整性约束违规的总括码,核心不直接使用。 活跃
40003 statement_completion_unknown ERRCODE_T_R_STATEMENT_COMPLETION_UNKNOWN ERROR 7.4
语句完成状态不确定,重试前先核对业务状态。 活跃
40P01 deadlock_detected ERRCODE_T_R_DEADLOCK_DETECTED ERROR 7.4
检测到死锁,事务因等待环被选为受害者中止。 活跃