22016 — invalid_argument_for_nth_value_function
nth_value 的序号必须大于零。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- invalid_argument_for_nth_value_function
- lang
- en
- sqlstate
- 22016
版本定义 PG 18
速览 {#at-a-glance}
nth_value 收到非正的序号。固定窗口函数路径以 SQLSTATE 22016 报告 argument of nth_value must be greater than zero。
含义 {#meaning}
window_nth_value 先读取序号参数:NULL 返回 NULL,小于等于零才抛出 22016。正序号随后转换为从帧头开始的零基偏移。如果目标行不在当前帧内,或选中的值本身为 NULL,执行器返回 NULL;这两种情况都不是 22016。
诊断 {#diagnosis}
检查序号实际值、窗口排序和帧边界。区分无效的非正参数与合法正参数但目标行不在帧内的情况。NULL 序号也是 NULL 结果路径,因此不能仅因结果为 NULL 就归为本码。
处理 {#response}
如果函数确实要选取某行,传入正序号;只有必须包含目标行时才调整排序或帧。若 NULL 表示帧中没有目标行或目标值本来为 NULL,应保留这个结果。非正 guard 抛出 ERROR;显式事务需先回滚或回到已有保存点再重试,自动提交只重试修正后的语句。
报文 {#messages}
- Primary,
ERROR:argument of nth_value must be greater than zero。 - 非正序号 guard 没有附加 DETAIL 或 HINT;超出帧和 NULL 值路径改为返回 NULL。
版本 {#versions}
锁定目录从 8.4.0 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的是窗口函数实现,不是一般序号校验器。
相关 {#related}
来源 {#sources}
src/backend/utils/adt/windowfuncs.c#L686-L715 展示 NULL 处理、正序号 guard、帧查找,以及没有目标行/值时返回 NULL。运行核验为 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": "22016 is invalid_argument_for_nth_value_function in SQLSTATE Class 22."
}claims · resolved-path
{
"claim_id": "resolved-path",
"limits": "",
"method": "Read the complete ordinal check, frame lookup, and NULL result path.",
"position": 1,
"runtime": [],
"sources": [
"src.nth-value.18.6"
],
"statement": "window_nth_value returns NULL for a NULL ordinal, raises 22016 for a non-positive ordinal, and returns NULL when a valid positive ordinal selects no row in the current frame or a NULL value."
}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 22016 from 8.4.0 without proving an exact implementation introduction date."
}messages · message.nonpositive-ordinal
{
"limits": "",
"message_id": "message.nonpositive-ordinal",
"path": "",
"position": 0,
"raw": {
"id": "message.nonpositive-ordinal",
"primary_template": "argument of nth_value must be greater than zero",
"severity_source": "ERROR",
"sources": [
"src.nth-value.18.6"
],
"sqlstate": "22016"
},
"severity": "ERROR",
"sources": [
"src.nth-value.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "argument of nth_value must be greater than zero",
"position": 0,
"role": "",
"template": "argument of nth_value must be greater than zero"
}
]
}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#L186"
}sources · src.nth-value.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/windowfuncs.c",
"position": 1,
"sha256": "49214f9325dcdd73728d08574b0b6843e90822a18bdaf6b0d49139b1eaae6b63",
"source_id": "src.nth-value.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/windowfuncs.c#L686-715"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:365850348911b2a708ee5835786ef8f5690bfaa8c9cfa8faeabbee6095b64d12
正文语言: zh-Hans · english-manuals:365850348911b2a708ee5835786ef8f5690bfaa8c9cfa8faeabbee6095b64d12