SQLSTATE 42P02 ERROR Class 42: Syntax Error or Access Rule Violation

undefined_parameter there is no parameter $N — 42P02

PostgreSQL error "there is no parameter $N" (SQLSTATE 42P02): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A query used a positional parameter placeholder ($n) for which no value was supplied. PostgreSQL raises SQLSTATE 42P02 (undefined_parameter).

  • A $n placeholder has no bound value.
  • Common when the parameter count doesn’t match the bound values.
  • Often off-by-one in driver parameter arrays.

What the server log shows

ERROR:  there is no parameter $2
LINE 1: SELECT * FROM orders WHERE id = $1 AND status = $2;

Why PostgreSQL raises this — what the manual says

As Section 4.3 Calling Functions explains:

A function call used a named argument whose name the function does not declare; named arguments must match the function’s declared parameter names exactly, so check the function signature or switch to positional notation.

Prepared/parameterized statements bind values to $1, $2, …. If the statement references a parameter number for which no value was provided, PostgreSQL cannot resolve it and reports 42P02.

Common causes

  • Fewer values bound than placeholders referenced.
  • An off-by-one in the driver’s parameter array.
  • Building SQL with a higher $n than parameters passed.

How to fix it

  1. Bind a value for every $n the statement uses.
  2. Ensure the parameter array length matches the highest placeholder.
  3. Check driver-specific parameter numbering (1-based).

Related & next steps

Reference: PostgreSQL 18 Section 4 “SQL Syntax”.

Was this helpful?