PostgreSQL error 42P02 (Undefined Parameter) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Count positional parameters ($1, $2, ...) and bind exactly that many values. If that does not apply, ensure the driver's parameter placeholders map to the correct positions — the full checklist is below.
SQLSTATE: 42P02
Official name: Undefined Parameter
Service: PostgreSQL
The referenced prepared-statement parameter does not exist.
PREPARE find(id int) AS SELECT * FROM users WHERE id = $1;
EXECUTE find(42);
The number of $N placeholders in PREPARE must equal the EXECUTE arguments; mismatches raise 42P02.
Pass params as a dict matching named placeholders; do not mix styles.
session.execute(text('SELECT * FROM u WHERE id = :id'), {'id': 1})
When calling RPCs with .rpc(), pass all declared parameters.
await supabase.rpc('get_user', { user_id: 1 })
Most often this happens when referencing $N where N exceeds the parameter count in a prepared statement, or when binding fewer parameters than the statement expects.
Count positional parameters ($1, $2, ...) and bind exactly that many values.
This page documents fixes for: sqlalchemy, supabase.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.