42P02: undefined_parameter
PostgreSQLWhat does it mean?
The query references a parameter that does not exist. PostgreSQL reports that the referenced positional parameter (e.g. $2) is not defined. Belongs to Class 42 (syntax_error_or_access_rule_violation).
Why does it happen?
Referencing more parameters than supplied in a statement prepared with PREPARE (e.g. sending two parameters and using $3); skipped parameter numbering; or wrong $N indexes in dynamically concatenated SQL.
How to fix it
Make sure the parameter numbers match the number of values you supply; verify they start at $1 and continue without gaps. Define parameter types completely in the PREPARE statement: PREPARE p(int, text) AS SELECT ... WHERE a=$1 AND b=$2; If you use an ORM/driver, compare the number of bound parameters with the placeholders in the query.