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.

What lands in your log

ERROR: there is no parameter $1

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

In 10 seconds

What triggers it
Type a bare query containing $1 directly into a client, with no PREPARE/parameter binding around it.
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.

Fix

What to do right now

Application-level steps for 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;

Verification

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

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops