PG
PRO
42P02ERRORTier 2 — Caution✅ HIGH confidence

undefined parameter

Category: Syntax Error or Access Rule ViolationVersions: All Postgres versions

What this means

SQLSTATE 42P02 is a Postgres-specific error raised when a query references a parameter ($n) that is beyond the number of parameters supplied — for example, using $3 when only 2 parameters were bound.

Why it happens

  1. 1A prepared statement references $3 but only 1 or 2 parameter values were provided
  2. 2Mismatch between the number of parameters in the statement and the number of values bound by the driver

How to reproduce

Prepared statement referencing an unbound parameter.

trigger — this will ERROR
PREPARE stmt AS SELECT * FROM orders WHERE id = $1 AND status = $3;
EXECUTE stmt(1, 'open'); -- $3 not supplied
ERROR: there is no parameter $3

Fix 1: Ensure all referenced parameters have corresponding bound values

When using PREPARE/EXECUTE or driver-level parameterised queries.

fix
PREPARE stmt AS SELECT * FROM orders WHERE id = $1 AND status = $2;
EXECUTE stmt(1, 'open');

Why this works

The number of $n placeholders must match the number of values supplied in the EXECUTE call or driver binding.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 42 — Syntax Error or Access Rule Violation (Postgres-specific)

Confidence assessment

✅ HIGH confidence

Postgres-specific. Stable across all versions.

See also

📄 Reference pages

PREPAREParameterised QueriesEXECUTE
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →