22011 — substring_error
substring 长度参数为负等取子串错误。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- substring_error
- lang
- en
- sqlstate
- 22011
版本定义 PG 18
速览 {#at-a-glance}
文本子字符串路径收到无效的显式长度。固定的 PostgreSQL 18.6 代码中,text_substring 以 SQLSTATE 22011 报告 negative substring length not allowed。
含义 {#meaning}
三参数文本子字符串包装器把显式长度传给 text_substring;负长度会进入 ERRCODE_SUBSTRING_ERROR guard。无长度包装器则传入带有 length_not_specified 的哨兵值,返回剩余文本,不会进入负长度 guard。OVERLAY 的起点不为正时也复用这个报错。本证据针对文本路径;bytea、位串和基于模式的 substring 有各自的消费者,应以完整诊断识别。
诊断 {#diagnosis}
修改前先确认解析出的操作和数据类型。对文本路径,要区分显式负长度与零或负起点:源码把有效起点调整为 1,并按 SQL 规则调整长度。起点超过末尾会返回空串。起点加长度的 32 位计算溢出时,子串延伸到末尾,并不报本码。OVERLAY 的非正起点使用同一 primary,而起点加长度溢出则使用 22003。
处理 {#response}
传入非负的显式文本长度;若意图是取到末尾,则省略长度。保留预期的一基起点语义,并在修复前确认实际数据类型。该路径抛出 ERROR;显式事务需先 ROLLBACK 或回到已有保存点后再重试,自动提交只重试修正后的语句。
报文 {#messages}
- Primary,
ERROR:显式文本子字符串 guard 和非正OVERLAY起点 guard 都是negative substring length not allowed;这些路径没有固定 DETAIL 或 HINT。
版本 {#versions}
锁定目录从 7.4 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的 guard 是当前版本的文本和 OVERLAY 路径,不推广到所有 substring 实现。
相关 {#related}
来源 {#sources}
src/backend/utils/adt/varlena.c#L896-L1010包含文本包装器、起点调整、省略长度哨兵、显式负长度ERROR以及末尾/溢出处理。src/backend/utils/adt/varlena.c#L1166-L1186包含OVERLAYguard 及其独立的22003溢出分支。
运行核验为 not_run;上述源码证据不是运行观察。结构化证据记录保留确切 primary 和源码范围。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read the fixed errcodes row and macro.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "22011 is substring_error in SQLSTATE Class 22."
}claims · resolved-text-path
{
"claim_id": "resolved-text-path",
"limits": "This is the fixed text path; other substring data types have separate consumers.",
"method": "Read the complete text_substring wrapper and guard.",
"position": 1,
"runtime": [],
"sources": [
"src.text-substring.18.6"
],
"statement": "The fixed text_substring path raises 22011 only for an explicit negative length; the omitted-length sentinel returns the remainder and the start/end calculations cover empty and overflow cases."
}claims · resolved-overlay-path
{
"claim_id": "resolved-overlay-path",
"limits": "",
"method": "Read the complete OVERLAY guard and overflow branch.",
"position": 2,
"runtime": [],
"sources": [
"src.overlay.18.6"
],
"statement": "The fixed OVERLAY path reuses the 22011 primary for a non-positive start, while an overflowing start-plus-length uses 22003."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue presence and history boundaries.",
"position": 3,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 22011 from 7.4 without proving an exact implementation introduction date."
}messages · message.text-negative-length
{
"limits": "Explicit negative text length.",
"message_id": "message.text-negative-length",
"path": "",
"position": 0,
"raw": {
"id": "message.text-negative-length",
"limits": "Explicit negative text length.",
"primary_template": "negative substring length not allowed",
"severity_source": "ERROR",
"sources": [
"src.text-substring.18.6"
],
"sqlstate": "22011"
},
"severity": "ERROR",
"sources": [
"src.text-substring.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "negative substring length not allowed",
"position": 0,
"role": "",
"template": "negative substring length not allowed"
}
]
}messages · message.overlay-nonpositive-start
{
"limits": "Non-positive OVERLAY start; this is not the OVERLAY overflow branch.",
"message_id": "message.overlay-nonpositive-start",
"path": "",
"position": 1,
"raw": {
"id": "message.overlay-nonpositive-start",
"limits": "Non-positive OVERLAY start; this is not the OVERLAY overflow branch.",
"primary_template": "negative substring length not allowed",
"severity_source": "ERROR",
"sources": [
"src.overlay.18.6"
],
"sqlstate": "22011"
},
"severity": "ERROR",
"sources": [
"src.overlay.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "negative substring length not allowed",
"position": 0,
"role": "",
"template": "negative substring length not allowed"
}
]
}sources · src.errcodes.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L180"
}sources · src.text-substring.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/varlena.c",
"position": 1,
"sha256": "fd4fa7e214370cabeec0a33792533e4f10037ba763ca1c433ae8795f9f04cd3c",
"source_id": "src.text-substring.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/varlena.c#L896-1010"
}sources · src.overlay.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/varlena.c",
"position": 2,
"sha256": "fd4fa7e214370cabeec0a33792533e4f10037ba763ca1c433ae8795f9f04cd3c",
"source_id": "src.overlay.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/varlena.c#L1166-1186"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:cb848e6212751c16d95ca7d93968f07d40c77f94cce3926b2c0994005e1e8880
正文语言: zh-Hans · english-manuals:cb848e6212751c16d95ca7d93968f07d40c77f94cce3926b2c0994005e1e8880