26000
PostgreSQLERRORNotableInvalid SQL Statement NameHIGH confidence

invalid SQL statement name

What this means

SQLSTATE 26000 is raised when a named prepared statement referenced by EXECUTE, DEALLOCATE, or DESCRIBE does not exist — it was never prepared or was already deallocated.

Why it happens
  1. 1Calling EXECUTE on a prepared statement name that was never created with PREPARE
  2. 2Calling EXECUTE after the prepared statement was deallocated with DEALLOCATE
  3. 3Session reconnect after which prepared statements were lost (connections do not persist prepared statements)
How to reproduce

EXECUTE on a non-existent prepared statement.

trigger — this will error
trigger — this will error
EXECUTE my_stmt(1, 'test'); -- my_stmt was never prepared in this session

expected output

ERROR:  prepared statement "my_stmt" does not exist

Fix 1

Prepare the statement before executing it

WHEN When using explicit SQL-level PREPARE/EXECUTE.

Prepare the statement before executing it
PREPARE my_stmt (INT, TEXT) AS
  SELECT * FROM orders WHERE id = $1 AND status = $2;
EXECUTE my_stmt(1, 'open');

Why this works

PREPARE must be called in the same session before EXECUTE. Prepared statements do not persist across connections.

Fix 2

Use driver-level prepared statements rather than SQL PREPARE

WHEN When using application-level drivers (JDBC, psycopg2, node-postgres).

Why this works

Driver-level prepared statements handle preparation transparently and re-prepare automatically on reconnect.

Sources
Official documentation ↗

Class 26 — Invalid SQL Statement Name

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

← All PostgreSQL errors