↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

42P02 — Undefined parameter

42P02 (undefined_parameter) is a parse-time ERROR because a positional marker such as $1 is outside the parameter set known to parse analysis. It differs from a Bind-message count violation (08P01) and from 42P08, where a known parameter cannot receive a consistent type.

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
Syntax Error or Access Rule Violation
condition name
undefined_parameter
lang
en
sqlstate
42P02

Definition PG 18

42P02 — Undefined parameter

At a glance {#at-a-glance}

42P02 (undefined_parameter) is a parse-time ERROR because a positional marker such as $1 is outside the parameter set known to parse analysis. It differs from a Bind-message count violation (08P01) and from 42P08, where a known parameter cannot receive a consistent type.

Meaning {#meaning}

The fixed-parameter hook rejects a parameter number outside the declared array or with an invalid type. The variable-parameter hook can grow its array while parsing, but its resolution checks still reject an out-of-range parameter. The generic parser hook reports the same primary when no hook resolves the marker. All selected branches attach parser position and use the dynamic number in there is no parameter $%d; this is about SQL ParamRef markers, not a missing column or PL/pgSQL variable.

The extended-query boundary is separate: exec_bind_message checks the number of parameter formats and values against the prepared statement and reports 08P01 for a count mismatch, including bind message supplies %d parameters, but prepared statement "%s" requires %d. A value-count or format-count failure during Bind therefore should not be relabeled as 42P02.

Diagnosis {#diagnosis}

Capture the SQL text, parser position, parameter number, and protocol phase. During Parse/parse analysis, compare every $n with the declared fixed or variable parameter set. During extended-query Bind, compare the format count and value count with the prepared statement and route a mismatch to 08P01; a missing SQL marker mapping is a different problem. Keep 42P08 for a parameter that exists but receives incompatible type deductions.

Response {#response}

Fix the SQL placeholder numbering or the Parse parameter declaration. In the Bind phase, send exactly the prepared statement's required parameter count and a compatible format-code count; do not try to cure a count mismatch with a cast. For a genuine missing marker, add the intended parameter or use a deliberate literal/default. If the ERROR occurred inside an explicit transaction, roll back to a suitable savepoint or roll back the transaction before retrying; no runtime recovery is claimed here.

Messages {#messages}

The selected parser groups are explicit ERROR with there is no parameter $%d; %d is the dynamic referenced parameter number. The separate fixed 18.6 Bind guards are explicit 08P01, with bind message has %d parameter formats but %d parameters or bind message supplies %d parameters, but prepared statement "%s" requires %d.

Versions {#versions}

From the locked 7.4 lower bound through 18.6 and 19beta3; that is a catalogue range, not a runtime comparison. The selected parser and Bind branches are fixed 18.6 source paths; no client bind case was run.

Related {#related}

Sources {#sources}

  • src.errcodes.42P02.18.6 — src/backend/utils/errcodes.txt line 375, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba (source).

  • src.call.42P02.81f0048a16f439569ce3a4ba — src/backend/parser/parse_expr.c lines 899-902, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 63c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b (source).

  • src.call.42P02.73515542f469d69893fd5fb8 — src/backend/parser/parse_param.c lines 109-112, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28 (source).

  • src.call.42P02.671f865f9d428e0ab2a78347 — src/backend/parser/parse_param.c lines 203-206, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28 (source).

  • src.call.42P02.bind-contract — src/backend/tcop/postgres.c lines 1718-1731, fixed at 724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-256 9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061 (source).

  • src.calls.REL_18_6.42P02 — resolved core call groups; SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf.

  • authored evidence — source claims, message roles, and runtime boundary.

Compare versions

SQLSTATE evidence and recorded runtime versions

claims · identity.class-and-condition
{
  "claim_id": "identity.class-and-condition",
  "limits": "Identity does not enumerate all source branches or client failures.",
  "method": "Read fixed REL_18_6 errcodes.txt and locked facts.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.42P02.18.6"
  ],
  "statement": "42P02 is the undefined_parameter condition in Class 42."
}
claims · mechanism.selected-source-path
{
  "claim_id": "mechanism.selected-source-path",
  "limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
  "method": "Read complete resolved REL_18_6 report groups and message roles.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.call.42P02.81f0048a16f439569ce3a4ba",
    "src.call.42P02.73515542f469d69893fd5fb8",
    "src.call.42P02.671f865f9d428e0ab2a78347",
    "src.call.42P02.bind-contract"
  ],
  "statement": "Fixed and variable parser parameter hooks report `there is no parameter $%d` with parser position when a marker is outside the known parameter set. The separate extended-query Bind guards report protocol violation 08P01 for parameter format/value counts that do not match the prepared statement, so a Bind count mismatch is not 42P02."
}
claims · versions.catalogue-boundary
{
  "claim_id": "versions.catalogue-boundary",
  "limits": "First observed release is a lower bound, not precise behavioral introduction.",
  "method": "Read locked catalogue facts and definition snapshots.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.42P02.18.6"
  ],
  "statement": "From the locked 7.4 lower bound through 18.6 and 19beta3; this is a catalogue range. The selected parser and Bind branches are fixed 18.6 source paths and no client bind case was run."
}
messages · message.variant-1
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-1",
  "path": "",
  "position": 0,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-1",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "there is no parameter $%d",
    "roles": [
      {
        "role": "errmsg",
        "template": "there is no parameter $%d"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P02.81f0048a16f439569ce3a4ba"
    ],
    "sqlstate": "42P02"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P02.81f0048a16f439569ce3a4ba"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "there is no parameter $",
      "position": 0,
      "role": "",
      "template": "there is no parameter $%d"
    }
  ]
}
messages · message.variant-2
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-2",
  "path": "",
  "position": 1,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-2",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "there is no parameter $%d",
    "roles": [
      {
        "role": "errmsg",
        "template": "there is no parameter $%d"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P02.73515542f469d69893fd5fb8"
    ],
    "sqlstate": "42P02"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P02.73515542f469d69893fd5fb8"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "there is no parameter $",
      "position": 0,
      "role": "",
      "template": "there is no parameter $%d"
    }
  ]
}
messages · message.variant-3
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-3",
  "path": "",
  "position": 2,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-3",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "there is no parameter $%d",
    "roles": [
      {
        "role": "errmsg",
        "template": "there is no parameter $%d"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P02.671f865f9d428e0ab2a78347"
    ],
    "sqlstate": "42P02"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P02.671f865f9d428e0ab2a78347"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "there is no parameter $",
      "position": 0,
      "role": "",
      "template": "there is no parameter $%d"
    }
  ]
}
sources · src.errcodes.42P02.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 375",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P02.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L375"
}
sources · src.call.42P02.81f0048a16f439569ce3a4ba
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 899-902",
  "path": "src/backend/parser/parse_expr.c",
  "position": 1,
  "sha256": "63c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b",
  "source_id": "src.call.42P02.81f0048a16f439569ce3a4ba",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_expr.c#L899-L902"
}
sources · src.call.42P02.73515542f469d69893fd5fb8
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 109-112",
  "path": "src/backend/parser/parse_param.c",
  "position": 2,
  "sha256": "4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28",
  "source_id": "src.call.42P02.73515542f469d69893fd5fb8",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_param.c#L109-L112"
}
sources · src.call.42P02.671f865f9d428e0ab2a78347
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 203-206",
  "path": "src/backend/parser/parse_param.c",
  "position": 3,
  "sha256": "4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28",
  "source_id": "src.call.42P02.671f865f9d428e0ab2a78347",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_param.c#L203-L206"
}
sources · src.call.42P02.bind-contract
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 1718-1731",
  "path": "src/backend/tcop/postgres.c",
  "position": 4,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.call.42P02.bind-contract",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L1718-L1731"
}
sources · src.calls.REL_18_6.42P02
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 5,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6.42P02",
  "tag": "",
  "url": ""
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:6832f8931981680f813099537998b83c507a976b00aa7f51fbfc4c022c1d0d69

Text language: en · english-manuals:6832f8931981680f813099537998b83c507a976b00aa7f51fbfc4c022c1d0d69