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

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

百科 / 错误代码 / Class 22 数据异常

22P05 untranslatable_character

ERROR 源码确认 参考 未实测

类别
Class 22 数据异常
严重等级
ERROR
条件名
untranslatable_character
宏名称
ERRCODE_UNTRANSLATABLE_CHARACTER
启用版本
7.4
状态
活跃

版本覆盖

速览

PostgreSQL 能识别源字符,却无法在目标编码中表示它。固定辅助函数 以 ERROR 发出 character with byte sequence %s in encoding "%s" has no equivalent in encoding "%s",其中包含字节序列和两种编码名。

含义

report_untranslatable_char(src_encoding, dest_encoding, ...) 计算源多字节字符长度,把问题字节格式化为 0x..,当目标转换表没有等价字符时抛出 22P05。也就是说源字符已经足够合法、可以识别,但目标表示无法承载它。它不同于坏源字节:固定转换循环可以调用 report_invalid_encoding,后者使用 22021

报文

  • ERROR 主消息:character with byte sequence %s in encoding "%s" has no equivalent in encoding "%s"
  • 固定调用没有 DETAIL 或 HINT。

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 character with byte sequence %s in encoding "%s" has no equivalent in encoding "%s"

来源:src/backend/utils/mb/mbutils.c @ REL_18_6

诊断

读取主消息中的字节序列、源编码、目标编码和转换方向。检查 client_encoding、服务器/数据库编码、导入或 COPY 文件编码及实际转换边界。不能仅因字符是非 ASCII 就认定是 22P05;坏源字节和普通类型输入失败走不同路径。

处理

选择能够表示数据的目标编码,或修正生产端和转换边界,同时保留该字符。除非业务明确允许有损处理,不要静默替换或丢弃。引用路径是 ERROR:显式事务中重试前执行 ROLLBACKROLLBACK TO SAVEPOINT;自动提交模式下修正编码或输入后重新提交。该源码路径不表示 FATAL 或必须重置连接。

版本

锁定目录从 PostgreSQL 7.4 记录此条件。引用的报告辅助函数 和代表性转换分支来自 PostgreSQL 18.6 REL_18_6;本次没有运行编码转换案例。

来源

证据

断言

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

  • 22P05 is untranslatable_character in SQLSTATE Class 22.

    核实方式Read fixed definition.

    来源src/backend/utils/errcodes.txt

  • report_untranslatable_char computes source multibyte character bytes and reports source and destination encoding names when conversion has no equivalent destination character.

    核实方式Read the complete reporting function.

    来源src/backend/utils/mb/mbutils.c

  • The conversion loop calls report_untranslatable_char for a valid source character with no destination mapping, while malformed remaining UTF-8 bytes fall through to report_invalid_encoding and 22021.

    核实方式Read the conversion failure and invalid-input branches.

    不覆盖The cited loop is representative; other conversion procedures call the same reporting helper.

    来源src/backend/utils/mb/conv.c · src/backend/utils/mb/mbutils.c

  • The locked catalogue records 22P05 from 7.4; that boundary does not prove exact implementation introduction.

    核实方式Use catalogue boundary.

    来源src/backend/utils/errcodes.txt

同类错误代码

Class 22 数据异常 下的其他成员。