SQLSTATE 42P02Severity lowLab verified

Incident brief

Undefined parameter

A query referenced a positional parameter ($1, $2, ...) outside of any context that supplies a value for it. PostgreSQL had nothing to substitute.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Undefined parameter
What triggers it
Type a bare query containing $1 directly into a client, with no PREPARE/parameter binding around it.
The fix
Only use $1, $2, ... inside a PREPARE'd statement (then supply values via EXECUTE), or via your client library's real parameter-binding API.
Proof
Reproduced on PostgreSQL 16.14 → A bare SELECT $1 typed directly, with no surrounding PREPARE, was rejected with SQLSTATE 42P02. The session was unaffected afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Only use $1, $2, ... inside a PREPARE'd statement (then supply values via EXECUTE), or via your client library's real parameter-binding API.
  • Never paste a $n placeholder into ad-hoc SQL text and run it directly — there is nothing to bind it to.
  • A parameter-count mismatch caught later, at EXECUTE time, surfaces as a different SQLSTATE entirely — see the counterexample.
Fix — SQL
PREPARE fetch_one(int) AS SELECT $1;
EXECUTE fetch_one(5);
DEALLOCATE fetch_one;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed