26000
Read PG 18 manual ↗invalid_sql_statement_name
- SQLSTATE
- 26000
- Condition name
- invalid_sql_statement_name
- Class
- Invalid SQL Statement Name
- Source macro
- ERRCODE_INVALID_SQL_STATEMENT_NAME
- Evidence
- Observed at runtime in the source evidence
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
26000 means that PostgreSQL was asked to use a named prepared statement that does not exist in the current backend session. It is a session-resource lookup failure, so first check session affinity and statement lifecycle before changing the SQL text.
Meaning
PREPARE registers a named statement in one PostgreSQL session. EXECUTE and DEALLOCATE resolve that name in the same session; a pool checkout can silently move the next command to another backend. The core prepare.c path reports the dynamic name with prepared statement "%s" does not exist. The fixed extended-query path in postgres.c separately reports unnamed prepared statement does not exist when the unnamed statement is absent.
Diagnosis
Read the driver exception's SQLSTATE and primary message, then log the backend PID or an equivalent connection identity around PREPARE and EXECUTE. On that same connection, pg_prepared_statements can show whether the named entry exists; querying it on a different pooled connection is not evidence about the failing session. Distinguish a deallocation, a connection replacement, and an unnamed statement path from a malformed PREPARE statement.
Response
If the operation is inside an explicit transaction, roll back the failed block before issuing more commands. Recreate the statement on the session that will execute it, and keep the statement definition and parameter types under the same application or pool checkout. A missing statement has not itself applied the intended operation, but the application should still use its normal request identity and side-effect checks before repeating a larger workflow.
Messages
The fixed core templates include prepared statement "%s" does not exist from prepare.c and unnamed prepared statement does not exist from the extended-query path in postgres.c. The selected case reports source_file = prepare.c and source_function = FetchPreparedStatement; only the named template has a server-side name substitution. Do not parse either message as a stable error string; branch on SQLSTATE and structured diagnostics.
Representative case
The runner reads this sequence from verify/cases/26000/snippets.json (SHA-256 b9fdbb48371e0d9902cb9e055ececc4878c38422773a8a1571651d9952809032) and keeps every statement on one connection. The complete executable record is the public case export, with structured evidence.
PREPARE statement_name(integer) AS SELECT $1 + 1;
EXECUTE statement_name(1);
DEALLOCATE statement_name;
EXECUTE statement_name(1);
statement_name is a page-level placeholder. The runner substitutes a unique identifier, deallocates it, asserts 26000 and IDLE, then repeats the registry's same three statements—PREPARE, EXECUTE, and DEALLOCATE—to repair the session. The recovery sequence is therefore: PREPARE the named statement again, EXECUTE it on that same connection, and DEALLOCATE it when the checkout is finished; these are the existing prepare, execute, and deallocate registry statements, not a second SQL definition.
The selected runner case observed 26000 on PostgreSQL 18.6 and 10.21. It deallocated a named statement, observed the dynamic missing-name diagnostic with the connection IDLE, then recreated and executed the statement on that same session.
Versions
The locked catalogue reports this condition from the early historical boundary through the current formal snapshots. The fixed 18.6 source has both named and unnamed prepared-statement paths; the runtime comparison covers one named path on 18.6 and 10.21. The message wording and source line can vary by release, while the SQLSTATE identity remains 26000 in the selected targets.
Sources
src.errcodes.18.6(SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)src.prepare.18.6(SHA-256e37fbd5f7618e5554561d9293d8c3af7cf3190c62c5c6bbceb3fe8b97be17956)src.postgres.18.6(SHA-2569fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061)PREPARE documentation· local call scansrc.calls.REL_18_6(SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
26000 is the invalid_sql_statement_name condition in Class 26.
Method: Read the fixed errcodes.txt row and macro mapping.
Limits: The definition does not identify which SQL statement resource is missing.
FetchPreparedStatement emits the source template prepared statement "%s" does not exist when a named prepared statement is absent.
Method: Trace ERRCODE_UNDEFINED_PSTATEMENT and errmsg in prepare.c.
Limits: The name is dynamic; this source path is from REL_18_6.
The fixed postgres.c extended-query path emits unnamed prepared statement does not exist with SQLSTATE 26000 when the unnamed prepared statement is absent.
Method: Trace ERRCODE_UNDEFINED_PSTATEMENT and errmsg in the fixed unnamed-statement protocol path.
Limits: This is a protocol/extended-query path and is not the selected named-statement runtime case; the message has no server-side name substitution.
PREPARE creates a session-local named statement; DEALLOCATE removes it, so EXECUTE must run on the same backend where the statement was created.
Method: Use the fixed PREPARE/EXECUTE documentation and the runner case lifecycle.
Limits: Connection pools can change backend sessions; this is a client/pool condition, not a promise about a particular driver.
The selected 26000 case passed on PostgreSQL 18.6 and 10.21 with the structured SQLSTATE, transaction-state, and repair assertions recorded in the runtime entries.
Method: Read the selected runner summaries and raw outputs tied to the shared snippet registry.
Limits: This covers the selected mechanism only, not all source callers or all driver/pool behavior.
runtime.26000-batch34-latest-20260909.latest runtime.26000-batch34-pg10-20260909.pg10
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·- src/backend/commands/prepare.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/tcop/postgres.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - doc/src/sgml/ref/prepare.sgml · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · message.prepared-missing
Primary
prepared statement "%s" does not exist
The unnamed prepared-statement path has a separate source template.
ERROR · message.unnamed-prepared-missing
Primary
unnamed prepared statement does not exist
This fixed protocol path has no server-side statement-name substitution.
Reproduction & repair cases
prepared_statement_recovery · PG 10, 18
Preconditions
- A runner-owned disposable target is provisioned.
Trigger: Prepare a named statement, deallocate it, then execute the missing name on the same session.
Expected assertions
- SQLSTATE is 26000
- The prepared statement name is in the diagnostic
- The same session can recreate and execute the statement after the error
Repair: Recreate the prepared statement on the session that will execute it; prepared statements are session-local.
Cleanup: Drop the case schema with an owner connection.
Recorded runtime evidence
18.6 (Homebrew) · passed
Run: 26000-batch34-latest-20260909
{
"repair": {
"values": {
"after_recreate": 2,
"before_deallocate": 2
}
},
"primary": "prepared statement \"prepared_recovery_a347d8\" does not exist",
"severity": "ERROR",
"sqlstate": "26000",
"statuses": {
"after_missing": "IDLE",
"after_recreate": "IDLE"
},
"connection_autocommit": true
}10.21 (Debian 10.21-1.pgdg90+1) · passed
Run: 26000-batch34-pg10-20260909
{
"repair": {
"values": {
"after_recreate": 2,
"before_deallocate": 2
}
},
"primary": "prepared statement \"prepared_recovery_8e5c66\" does not exist",
"severity": "ERROR",
"sqlstate": "26000",
"statuses": {
"after_missing": "IDLE",
"after_recreate": "IDLE"
},
"connection_autocommit": true
}Definition snapshot: english-manuals:3229543b42806bf449cc6234617… · English manual source