SQLSTATE 26000 ERROR Class 26: Invalid SQL Statement Name

invalid_sql_statement_name Invalid Sql Statement Name — SQLSTATE 26000

A prepared statement name does not exist on the server.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Symptoms

A prepared statement name does not exist on the server.

  • The error is written to the server log and returned to the client carrying SQLSTATE 26000.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN invalid_sql_statement_name THEN.

Environment

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).

Root Cause

EXECUTE referenced a prepared statement that was never prepared on this connection or was deallocated.

Common causes:

  • A pooler reset cleared server-side prepared statements.
  • DEALLOCATE ran before EXECUTE.
  • A name typo.

Diagnostic Queries

Recovery

Steps to resolve 26000:

  1. Prepare the statement on the same connection before executing it.
  2. With a transaction-pooling pooler (PgBouncer), disable server-side prepared statements or use a mode that preserves them.

Reference: PostgreSQL error codes — Class 26 (Invalid SQL Statement Name).

Was this helpful?