↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

22005 — error_in_assignment

赋值违反目标变量契约,如变量声明为 CONSTANT。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Data Exception
condition name
error_in_assignment
lang
en
sqlstate
22005

版本定义 PG 18

22005

速览 {#at-a-glance}

22005 是 error_in_assignment,表示赋值操作违反了目标变量的赋值契约。固定 PL/pgSQL 路径报告常量变量被赋值:variable "%s" is declared CONSTANT。

含义 {#meaning}

固定 PL/pgSQL 路径报告常量变量被赋值:variable "%s" is declared CONSTANT。

exec_check_assignable 会对 PL/pgSQL 变量、promise 变量和 isconst 为真的 record 执行该检查;record field 会递归检查父 record,而 row datum 本身可赋值。因此诊断时要结合 routine 上下文和报文中的 datum 名称。

报文 {#messages}

已确认分支以 ERROR 严重性报告 primary:variable "%s" is declared CONSTANT。固定源码没有 DETAIL 或 HINT。本页只有源码证据,没有自然运行观察。

诊断 {#diagnosis}

读取 message 中的变量名和 routine 上下文;固定路径是 PL/pgSQL 常量赋值错误,不是一般类型转换错误。

处置 {#response}

移除该赋值、在确需可变时调整声明,或写入另一个变量;先修正 routine 再重做业务操作。显式事务中,未捕获的 ERROR 会使事务失败,应回滚整个事务或回滚到调用前建立的保存点。若 routine 有意使用 PL/pgSQL EXCEPTION 块处理错误,则可由其子事务隔离;本页没有运行案例证明特定 handler 的行为。

版本 {#versions}

锁定目录从 7.4 记录该条件,并在列出的正式快照及 19beta3 中出现;固定源码覆盖为 PostgreSQL 18.6。

相关条件 {#related}

22000, 22001, 22003, 22004

来源 {#sources}

详见结构化的证据记录,其中列出固定源码链接与范围限制。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "22005 is error_in_assignment in SQLSTATE Class 22."
}
claims · mechanism.plpgsql-constant
{
  "claim_id": "mechanism.plpgsql-constant",
  "limits": "This does not classify every type conversion or target-column assignment error.",
  "method": "Read exec_check_assignable and its complete CONSTANT branch.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.plpgsql-constant"
  ],
  "statement": "PL/pgSQL assignment checking rejects writes to a variable marked CONSTANT and reports the variable name."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 22005 from 7.4 without proving an exact implementation introduction date."
}
messages · message.constant
{
  "limits": "",
  "message_id": "message.constant",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.constant",
    "primary_template": "variable \"%s\" is declared CONSTANT",
    "severity_source": "ERROR",
    "sources": [
      "src.path.plpgsql-constant"
    ],
    "sqlstate": "22005"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.plpgsql-constant"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "variable \" \" is declared CONSTANT",
      "position": 0,
      "role": "",
      "template": "variable \"%s\" is declared CONSTANT"
    }
  ]
}
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#L169"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 1,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}
sources · src.path.plpgsql-constant
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/pl/plpgsql/src/pl_exec.c",
  "position": 2,
  "sha256": "0df3c70a6bccf6dddf443fb99e152a16a67009827c44a820597e98e585cb8b20",
  "source_id": "src.path.plpgsql-constant",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/pl/plpgsql/src/pl_exec.c#L8565-L8582"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:22eedee16222cf143363d5ce6e269517898ddd768e757fa8d52c2649cc633334

正文语言: zh-Hans · english-manuals:22eedee16222cf143363d5ce6e269517898ddd768e757fa8d52c2649cc633334