22021 — character_not_in_repertoire
字节序列对目标编码无效。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- character_not_in_repertoire
- lang
- en
- sqlstate
- 22021
版本定义 PG 18
22021
速览 {#at-a-glance}
源字节序列对于正在检查的编码无效。固定转换路径报告 invalid byte sequence for encoding "%s": %s,并以十六进制列出违规字节。
含义 {#meaning}
report_invalid_encoding 计算不完整或无效多字节序列的长度,使用源编码名和十六进制字节发出 22021。有效的源字符若在目标编码中没有等价表示,则走独立的 22P05 untranslatable-character 路径;这不表示源字节本身损坏。
诊断 {#diagnosis}
在改动前记录源/目标编码、客户端/数据库设置以及原始字节。无效源字节指向输入或边界解码问题;可读但不可表示的字符指向目标编码的字符表示范围。不要把 SQL_ASCII 当作无条件修复:接受任意字节可能只是推迟或隐藏编码边界缺陷。
处理 {#response}
修复生产端或编码边界,或在保留违规字节的前提下按明确的丢弃/拒绝策略显式转换。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的输入。
版本 {#versions}
锁定目录从 7.4 起记录该条件;本页固定转换路径为 PostgreSQL 18.6。未声称本页有自然运行观察。
相关 {#related}
来源 {#sources}
无效字节报告器在 src/backend/utils/mb/mbutils.c#L1818-1853;同一固定文件的 report_untranslatable_char 路径对有效但不可表示字符发出独立 22P05。结构化证据记录保留两条边界;本页未运行自然案例。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read the fixed errcodes row and macro.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "22021 is character_not_in_repertoire in SQLSTATE Class 22"
}claims · resolved-path
{
"claim_id": "resolved-path",
"limits": "Source confirmation is not a natural runtime observation.",
"method": "Read complete source contexts for the representative guards.",
"position": 1,
"runtime": [],
"sources": [
"src.mbutils.invalid",
"src.mbutils.untranslatable"
],
"statement": "Fixed PostgreSQL 18.6 encoding helpers distinguish invalid source bytes (22021) from a valid source character with no destination equivalent (22P05)."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue presence and history boundaries.",
"position": 2,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 22021 from 7.4 without proving an exact implementation introduction date."
}messages · message.invalid-byte
{
"limits": "",
"message_id": "message.invalid-byte",
"path": "",
"position": 0,
"raw": {
"id": "message.invalid-byte",
"primary_template": "invalid byte sequence for encoding \"%s\": %s",
"severity_source": "ERROR",
"sources": [
"src.mbutils.invalid"
],
"sqlstate": "22021"
},
"severity": "ERROR",
"sources": [
"src.mbutils.invalid"
],
"templates": [
{
"kind": "primary",
"literal": "invalid byte sequence for encoding \" \":",
"position": 0,
"role": "",
"template": "invalid byte sequence for encoding \"%s\": %s"
}
]
}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#L165"
}sources · src.mbutils.invalid
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/mb/mbutils.c",
"position": 1,
"sha256": "2c034d792a3fbc402d673d6e08bd6a2198651bfd3c057176d4098f7e4a215dfb",
"source_id": "src.mbutils.invalid",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/mb/mbutils.c#L1818"
}sources · src.mbutils.untranslatable
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/mb/mbutils.c",
"position": 2,
"sha256": "2c034d792a3fbc402d673d6e08bd6a2198651bfd3c057176d4098f7e4a215dfb",
"source_id": "src.mbutils.untranslatable",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/mb/mbutils.c#L1861"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:cb95654efd6bf18765485d42f13c533cde44d1844f1d10235fa846faed4d1c34
正文语言: zh-Hans · english-manuals:cb95654efd6bf18765485d42f13c533cde44d1844f1d10235fa846faed4d1c34