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

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

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

22P01 floating_point_exception

ERROR 源码确认 参考 未实测

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

版本覆盖

速览

固定核心代码路径中的 FloatExceptionHandler 被注册为 SIGFPE 处理器。它以 ERROR 严重性发出主消息 floating-point exception,详细信息说明收到无效浮点操作信号,可能是结果越界或除零等无效操作。

含义

src/backend/tcop/postgres.c 中的 FloatExceptionHandler(SIGNAL_ARGS) 把信号转成 ereport(ERROR)PostgresMainSIGFPE 安装该处理器。这是浮点信号路径,不能据此说所有除法或数值越界都使用 22P01。精确数值除零和数值范围检查通常分别使用自己的 2201222003 条件。

诊断

保留完整 ErrorResponse 和服务器日志上下文,包括语句位置以及可用的 routine/context 字段。检查操作数类型和表达式路径,区分硬件或浮点无效操作与使用 2201222003 的精确数值运算。固定处理器的详细信息是诊断说明,不证明具体一定是除零。

报文

  • ERROR 主消息:floating-point exception
  • DETAIL:An invalid floating-point operation was signaled. This probably means an out-of-range result or an invalid operation, such as division by zero.

报文模板

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

主消息 floating-point exception
DETAIL An invalid floating-point operation was signaled. This probably means an out-of-range result or an invalid operation, such as division by zero.

来源:src/backend/tcop/postgres.c @ REL_18_6

处理

修正算术或输入范围;如果需要改变数值域,要在运算前明确转换。显式事务中,ERROR 会使事务进入中止状态,重试前执行 ROLLBACKROLLBACK TO SAVEPOINT;自动提交模式下先修正表达式或数据再重新提交。引用路径是 ERROR 而非 FATAL,普通客户端后端不会仅因该条件就需要重置连接。

版本

锁定目录从 PostgreSQL 7.4 记录此条件。本页引用的处理器和 SIGFPE 注册来自 PostgreSQL 18.6 REL_18_6;目录边界不能证明当前消息的精确引入版本。

来源

证据

断言

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

  • 22P01 is floating_point_exception in SQLSTATE Class 22.

    核实方式Read fixed definition.

    来源src/backend/utils/errcodes.txt

  • FloatExceptionHandler is the backend SIGFPE handler. It emits ERROR 22P01 with primary floating-point exception and detail about an invalid floating-point operation, an out-of-range result, or an invalid operation such as division by zero.

    核实方式Read the complete handler and the PostgresMain SIGFPE registration.

    不覆盖The source confirms the handler and message; it does not show a natural SIGFPE runtime in this review.

    来源src/backend/tcop/postgres.c · src/backend/tcop/postgres.c

  • The handler is distinct from type-specific exact-numeric errors such as division-by-zero 22012 and numeric range 22003.

    核实方式Compare the fixed handler with the condition-specific source boundary named in the page.

    不覆盖Related-code distinctions are diagnostic guidance, not a claim that every arithmetic operator chooses one code.

    来源src/backend/tcop/postgres.c

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

    核实方式Use catalogue boundary.

    来源src/backend/utils/errcodes.txt

同类错误代码

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