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

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

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

22014 invalid_argument_for_ntile_function

ERROR 源码确认 参考 未实测

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

版本覆盖

速览

ntile 收到非正的桶数量。固定窗口函数路径以 SQLSTATE 22014 报告 argument of ntile must be greater than zero

含义

context->ntile 仍为零、尚未成功初始化时,window_ntile 才会计算桶参数。参数为 NULL 时先返回 NULL,也不会设置这个状态,因此后续行可能再次计算参数;小于等于零时抛出 22014,正数则初始化状态并在后续行复用。空输入没有可供窗口函数计算的行,不属于这个错误。

诊断

检查受影响分区中 ntile 参数的解析值,区分三种情况:正数、NULL 和非正数。对实际求值的行,NULL 参数会给出 NULL;空分区则完全没有结果。二者都不应归为非正参数错误。

处理

检查提供参数的表达式后传入正整数桶数量。只有桶策略本来就允许时,才使用 COALESCE 或其他回退值。固定 guard 抛出 ERROR;显式事务需先回滚或回到已有保存点再重试,自动提交只重试修正后的语句。

报文

  • Primary,ERRORargument of ntile must be greater than zero
  • 固定 guard 没有附加 DETAIL 或 HINT。

报文模板

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

主消息 argument of ntile must be greater than zero

来源:src/backend/utils/adt/windowfuncs.c @ REL_18_6

版本

锁定目录从 8.4.0 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的是窗口函数实现,不是一般参数校验器。

来源

证据

断言

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

  • 22014 is invalid_argument_for_ntile_function in SQLSTATE Class 22.

    核实方式Read the fixed errcodes row and macro.

    来源src/backend/utils/errcodes.txt

  • When ntile state is still uninitialized, the function evaluates the bucket argument; NULL returns before initialization, non-positive raises 22014, and a positive count initializes and is reused for later rows.

    核实方式Read the complete window_ntile initialization, NULL, guard, and distribution path.

    不覆盖An empty input has no window-function row to evaluate.

    来源src/backend/utils/adt/windowfuncs.c

  • The locked catalogue records 22014 from 8.4.0 without proving an exact implementation introduction date.

    核实方式Use catalogue presence and history boundaries.

    来源src/backend/utils/errcodes.txt

同类错误代码

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