↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

22005 — error_in_assignment

22005 is errorinassignment. The fixed PL/pgSQL path reports assignment to a variable declared CONSTANT; ECPG and other assignment layers may have separate boundaries.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Data Exception
condition name
error_in_assignment
lang
en
sqlstate
22005

Definition PG 18

22005

At a glance {#at-a-glance}

22005 is error_in_assignment. The fixed PL/pgSQL path reports assignment to a variable declared CONSTANT; ECPG and other assignment layers may have separate boundaries.

Meaning {#meaning}

22005 is error_in_assignment. The fixed PL/pgSQL path reports assignment to a variable declared CONSTANT; ECPG and other assignment layers may have separate boundaries.

exec_check_assignable applies this guard to PL/pgSQL variables, promise variables, and records whose isconst flag is set. Record fields delegate the check to their parent record, while row datums are assignable; this is why the routine context and the named datum matter.

Messages {#messages}

The confirmed branch raises ERROR with primary variable "%s" is declared CONSTANT. It has no fixed DETAIL or HINT. This page is source-only; no natural runtime observation is claimed.

Diagnosis {#diagnosis}

Read the named variable and routine context. The confirmed path is a PL/pgSQL assignment contract, not a general type conversion or target-column error.

Response {#response}

Remove the assignment, change the declaration when mutability is intended, or assign to a separate variable. Correct the routine before rerunning its business operation. An uncaught ERROR in an explicit transaction leaves that transaction failed; roll it back or use a savepoint established before the call. A PL/pgSQL EXCEPTION block can contain the failure in its subtransaction when the routine is deliberately written to handle it; this page has no runtime case proving a particular handler.

Versions {#versions}

The locked catalogue records this condition from 7.4 in the listed formal snapshots and 19beta3; fixed source coverage is PostgreSQL 18.6.

Related {#related}

22000, 22001, 22003, 22004

Sources {#sources}

See the fixed source links and scope limits in the structured evidence record.

Compare versions

SQLSTATE evidence and recorded runtime versions

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"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:22eedee16222cf143363d5ce6e269517898ddd768e757fa8d52c2649cc633334

Text language: en · english-manuals:22eedee16222cf143363d5ce6e269517898ddd768e757fa8d52c2649cc633334