PostgreSQL 42P02: there is no parameter
The SQL contains a $1-style placeholder but no parameter value was bound, often from running driver SQL directly or from placeholders inside quotes.
- SQLSTATE
42P02- Name
undefined_parameter
What it means
PostgreSQL's own placeholders are $1, $2 and so on, filled in when a statement is prepared or executed with bound parameters. If the text contains $1 but the statement was sent without parameters, PostgreSQL has nothing to substitute and fails with 42P02 (undefined_parameter).
This usually means SQL copied from application code or a log was run by hand, or a driver sent a query string with placeholders through a path that doesn't bind them.
Common causes
- Running a parameterized query copied from code or logs in psql or a SQL editor.
- Placeholders inside a string or a dollar-quoted function body, where the driver doesn't substitute them.
- A
DOblock or dynamic SQL using$1withoutEXECUTE ... USING. - Mixing driver placeholder styles:
?or%sin one place,$1in another.
How to fix it
-
When running it by hand, replace the placeholders with literal values, or use
PREPAREandEXECUTE.PREPARE find_order(int) AS SELECT * FROM orders WHERE id = $1; EXECUTE find_order(42);
-
In dynamic SQL inside PL/pgSQL, pass values with
USING.DO $$ DECLARE n int; BEGIN EXECUTE 'SELECT count(*) FROM orders WHERE customer_id = $1' INTO n USING 42; RAISE NOTICE '%', n; END; $$; -
In application code, pass the values through the driver's parameter API rather than concatenating them.
Reproduce it safely
SELECT $1; -- ERROR: there is no parameter $1
Related errors
More syntax error or access rule violation errors
42501permission denied42846cannot coerce42803column must appear in the GROUP BY clause42830invalid foreign key42804datatype mismatch42703column does not exist42883function does not exist42P01relation does not exist
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.