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

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

文档 / SQL 状态码 / Class 23 完整性约束冲突

23000 integrity_constraint_violation

完整性约束冲突

ERROR 仅定义 参考 不适用

类别
Class 23 完整性约束冲突
严重等级
ERROR
条件名
integrity_constraint_violation
宏名称
ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION
启用版本
7.4
状态
活跃

版本覆盖

速览

23000 是 Class 23 完整性约束冲突的总类名,不是可以替代具体错误码的自然触发码。客户端应使用服务器返回的完整五字符 SQLSTATE。

含义

该类包含违反声明完整性规则的行和模式操作。锁定的 errcodes.txt 将具体机制分到 230012350223503235052351423P01 等子码;18.6 核心调用扫描没有解析出的 23000 报文路径,因此本文不伪造运行复现。

诊断

先读取精确 SQLSTATE,再查看 constraint_nametable_namecolumn_nameschema_name 以及主报文/DETAIL。把所有 Class 23 错误压成 23000 会丢失修复所需的对象和机制。

处理

保留原语句及事务边界,按具体子码修复数据或约束;显式事务报错后先回滚。不要用 RAISE ... ERRCODE 23000 冒充自然服务器机制。

源码报文模板

适用边界

本批没有为 23000 构造自然 SQL 触发器;请把它视为源码/协议边界,而不是可直接复制的复现脚本。结构化证据 · 案例导出

作者证据 ID:identity, specific-codes, handling。选定运行记录:—。

版本与边界

锁定目录在 7.4 已观察到该总类,并在列出的 9.0–18.6 正式快照中均存在。18.6 调用扫描确认了有界源码观察;本文不把它解释为扩展或未来版本都不可能发出该码。

来源

证据

断言

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

  • 23000 is the Class 23 integrity_constraint_violation umbrella condition.

    核实方式Read the fixed class and condition row.

    不覆盖The umbrella code is a protocol definition; concrete PostgreSQL constraint paths normally use a more specific Class 23 code.

    来源src/backend/utils/errcodes.txt

  • PostgreSQL source uses specific descendants such as 23001, 23502, 23503, 23505, 23514, and 23P01 for distinct mechanisms; the exhaustive 18.6 call scan has no resolved 23000 report group.

    核实方式Compare the errcodes mapping with all resolved report groups whose code_candidates contain 23000.

    不覆盖Absence from this scan is not proof that every extension or future source path can never emit 23000; it bounds this locked core scan.

    来源src/backend/utils/errcodes.txt · raw/calls/REL_18_6.jsonl

  • A client should branch on the exact five-character SQLSTATE and use constraint/object fields rather than collapsing every Class 23 error to 23000.

    核实方式Read the protocol identity and the specific descendant mappings.

    不覆盖Do not fabricate a natural 23000 reproduction with RAISE; this batch has no safe core SQL path for it.

    来源src/backend/utils/errcodes.txt

同类 SQL 状态码

状态码 条件名 宏名称 严重等级 版本
Class 23 完整性约束冲突 Integrity Constraint Violation 7 个
23000 integrity_constraint_violation ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION ERROR 7.4
完整性约束冲突的类别码,应使用具体子码。 活跃
23001 restrict_violation ERRCODE_RESTRICT_VIOLATION ERROR 7.4
外键 RESTRICT 动作拒绝删除仍被引用的父行。 活跃
23502 not_null_violation ERRCODE_NOT_NULL_VIOLATION ERROR 7.4
向 NOT NULL 列写入了 NULL 值。 活跃
23503 foreign_key_violation ERRCODE_FOREIGN_KEY_VIOLATION ERROR 7.4
外键约束冲突,子行找不到匹配的父键。 活跃
23505 unique_violation ERRCODE_UNIQUE_VIOLATION ERROR 7.4
行或索引违反唯一约束,常见于重复键插入。 活跃
23514 check_violation ERRCODE_CHECK_VIOLATION ERROR 7.4
CHECK 约束计算为假,写入的行不满足条件。 活跃
23P01 exclusion_violation ERRCODE_EXCLUSION_VIOLATION ERROR 9.0
排除约束发现新行与已有行冲突,如范围重叠。 活跃