// PostgreSQL error reference

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
Category
Syntax Error or Access Rule Violation
Error message
there is no parameter $1

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 DO block or dynamic SQL using $1 without EXECUTE ... USING.
  • Mixing driver placeholder styles: ? or %s in one place, $1 in another.

How to fix it

  1. When running it by hand, replace the placeholders with literal values, or use PREPARE and EXECUTE.

    PREPARE find_order(int) AS SELECT * FROM orders WHERE id = $1;
    EXECUTE find_order(42);
  2. 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;
    $$;
  3. 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

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.

// fewer errors, faster fixes

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.