Diagnostic Queries
Symptoms
A query used a positional parameter placeholder ($n) for which no value was supplied. PostgreSQL raises SQLSTATE 42P02 (undefined_parameter).
- A
$nplaceholder 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
$nthan parameters passed.
How to fix it
- Bind a value for every
$nthe statement uses. - Ensure the parameter array length matches the highest placeholder.
- Check driver-specific parameter numbering (1-based).
Related & next steps
Reference: PostgreSQL 18 Section 4 “SQL Syntax”.
Thanks — noted. This helps keep the database accurate.