2201E — invalid_argument_for_logarithm
对数函数参数为零或负数。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- invalid_argument_for_logarithm
- lang
- en
- sqlstate
- 2201E
版本定义 PG 18
2201E
速览 {#at-a-glance}
对数函数会在定义域守卫处拒绝零值和负值。固定浮点路径报告 cannot take logarithm of zero 或 cannot take logarithm of a negative number;numeric 的 ln 和给定底数的对数路径也使用该 SQLSTATE,但会分别处理 NaN 与无穷值。
含义 {#meaning}
2201E 是对数定义域错误,不是一般数值溢出。float.c 中 ln() 与 log() 先拒绝等于零的参数,再拒绝小于零的参数。numeric 的 ln 拒绝负无穷但原样返回 numeric NaN 或正无穷;numeric 的给定底数对数拒绝负值或零值输入,而某些正的特殊值组合有定义结果。
诊断 {#diagnosis}
先读函数签名和实际数值类型,再定位参数。按首要报文区分零值守卫与负值守卫。浮点 NaN 不满足这两个比较,因此不会进入这条具体守卫;后续浮点溢出或下溢属于其他条件。检查对数定义域是否符合业务意图,不要只为转换而转换。
处理 {#response}
提供符合目标对数函数定义域的值,或明确改变业务规则。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交客户端可直接重试修正后的语句。单纯 cast 不能使未定义运算变得有定义。
版本 {#versions}
锁定目录从 8.0.0 起记录该条件;本页固定源码路径为 PostgreSQL 18.6。未声称本页有自然运行观察。
相关 {#related}
来源 {#sources}
固定路径包括 src/backend/utils/adt/float.c#L1687-1747 和 src/backend/utils/adt/numeric.c#L3935-4020 以及 #L11156-11168,绑定零值/负值守卫及特殊值分支。结构化证据记录保留确切报文角色和范围;本页未运行自然案例。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read the fixed errcodes row and macro.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "2201E is invalid_argument_for_logarithm 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.float.log",
"src.numeric.log",
"src.numeric.ln.finite"
],
"statement": "Fixed PostgreSQL 18.6 float and numeric logarithm paths bind zero/negative guards and distinct NaN/infinity handling for both ln and base-log operations."
}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 2201E from 8.0.0 without proving an exact implementation introduction date."
}messages · message.zero
{
"limits": "",
"message_id": "message.zero",
"path": "",
"position": 0,
"raw": {
"id": "message.zero",
"primary_template": "cannot take logarithm of zero",
"severity_source": "ERROR",
"sources": [
"src.float.log",
"src.numeric.log",
"src.numeric.ln.finite"
],
"sqlstate": "2201E"
},
"severity": "ERROR",
"sources": [
"src.float.log",
"src.numeric.log",
"src.numeric.ln.finite"
],
"templates": [
{
"kind": "primary",
"literal": "cannot take logarithm of zero",
"position": 0,
"role": "",
"template": "cannot take logarithm of zero"
}
]
}messages · message.negative
{
"limits": "",
"message_id": "message.negative",
"path": "",
"position": 1,
"raw": {
"id": "message.negative",
"primary_template": "cannot take logarithm of a negative number",
"severity_source": "ERROR",
"sources": [
"src.float.log",
"src.numeric.log",
"src.numeric.ln.finite"
],
"sqlstate": "2201E"
},
"severity": "ERROR",
"sources": [
"src.float.log",
"src.numeric.log",
"src.numeric.ln.finite"
],
"templates": [
{
"kind": "primary",
"literal": "cannot take logarithm of a negative number",
"position": 0,
"role": "",
"template": "cannot take logarithm of a negative number"
}
]
}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#L173"
}sources · src.float.log
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/float.c",
"position": 1,
"sha256": "58914ae93c06c281e581a4bb2dcf2280e4ae1619f3ceb8f801f50beca87eecd8",
"source_id": "src.float.log",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/float.c#L1687"
}sources · src.numeric.log
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/numeric.c",
"position": 2,
"sha256": "6cde7cd60b3330b83be35d1f014045f5fb5fe737f3c5db4c8ed4080b99f2b666",
"source_id": "src.numeric.log",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/numeric.c#L3935"
}sources · src.numeric.ln.finite
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/numeric.c",
"position": 3,
"sha256": "6cde7cd60b3330b83be35d1f014045f5fb5fe737f3c5db4c8ed4080b99f2b666",
"source_id": "src.numeric.ln.finite",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/numeric.c#L11156"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:a92aece2256db02908d389611b2095ed53aa45d6da34ae4d4c5dda015e0264a8
正文语言: zh-Hans · english-manuals:a92aece2256db02908d389611b2095ed53aa45d6da34ae4d4c5dda015e0264a8