42P02
PostgreSQLERRORNotableSyntax Error or Access Rule ViolationHIGH confidence

undefined parameter

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
trigger — this will error
PREPARE stmt AS SELECT * FROM orders WHERE id = $1 AND status = $3;
EXECUTE stmt(1, 'open'); -- $3 not supplied

expected output

ERROR:  there is no parameter $3

Fix

Ensure all referenced parameters have corresponding bound values

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

Ensure all referenced parameters have corresponding bound values
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 documentation ↗

Class 42 — Syntax Error or Access Rule Violation (Postgres-specific)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors