26000 — invalid_sql_statement_name(预备语句名称无效)
会话中不存在该名称的预备语句。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Invalid SQL Statement Name
- condition name
- invalid_sql_statement_name
- lang
- en
- sqlstate
- 26000
版本定义 PG 18
26000 — invalid_sql_statement_name(预备语句名称无效)
速览 {#at-a-glance}
26000 表示 PostgreSQL 被要求使用当前后端会话中不存在的命名预备语句。这是会话资源查找失败,先检查会话是否保持不变以及语句生命周期,再修改 SQL 文本。
含义 {#meaning}
PREPARE 会在一个 PostgreSQL 会话中注册命名语句;EXECUTE 和 DEALLOCATE 也必须在同一会话按名称查找。连接池可能在两次操作之间换了后端。核心 prepare.c 路径使用 prepared statement "%s" does not exist,其中名称由服务器动态填入;固定的扩展查询路径还会在未命名语句不存在时使用 postgres.c 的 unnamed prepared statement does not exist。
诊断 {#diagnosis}
先读取驱动异常中的 SQLSTATE 和主报文,并在 PREPARE、EXECUTE 周围记录后端 PID 或同等连接身份。在同一连接上查询 pg_prepared_statements,才能判断该失败会话是否存在这个名称;在另一个池连接上查询不能证明失败会话的状态。区分显式 DEALLOCATE、连接被替换和未命名语句路径,不要把它误判成 PREPARE 语法错误。
处理 {#response}
如果命令位于显式事务中,先回滚失败块,再继续发命令。在真正执行它的会话上重新 PREPARE,并让应用或连接池在同一次 checkout 中完成定义和参数绑定。缺少语句本身没有执行预期操作,但重复更大的业务流程前仍应按业务请求标识和副作用检查执行正常校验。
报文 {#messages}
固定源码模板包括 prepare.c 的 prepared statement "%s" does not exist,以及扩展查询路径 postgres.c 的 unnamed prepared statement does not exist。选定案例记录的是 source_file = prepare.c、source_function = FetchPreparedStatement;只有命名模板带服务器端名称替换。应根据 SQLSTATE 和结构化诊断分支,不要把任一报文当成稳定完整字符串。
代表案例 {#case}
运行器从 verify/cases/26000/snippets.json(SHA-256 b9fdbb48371e0d9902cb9e055ececc4878c38422773a8a1571651d9952809032)读取下面的序列,并保证所有语句在同一连接执行;完整结果见公开案例导出和结构化证据。
PREPARE statement_name(integer) AS SELECT $1 + 1;
EXECUTE statement_name(1);
DEALLOCATE statement_name;
EXECUTE statement_name(1);
statement_name 是页面中的占位符。运行器会替换为唯一名称,释放它,断言 26000 和 IDLE,随后重复 registry 中同一组 PREPARE、EXECUTE、DEALLOCATE 三条语句修复会话。也就是说,恢复步骤是:在同一连接重新 PREPARE,执行它,并在 checkout 结束时 DEALLOCATE;引用的是现有 prepare、execute、deallocate registry 语句,而不是第二套 SQL 定义。
选定运行案例在 PostgreSQL 18.6 和 10.21 观察到 26000:先释放同名预备语句,再在同一会话执行它,得到带动态名称的诊断,连接保持 IDLE;随后重新 PREPARE 并成功执行。
版本 {#versions}
锁定目录从早期历史边界到当前正式快照都记录了该条件。18.6 固定源码同时包含命名和未命名预备语句路径;运行比较只覆盖 18.6 与 10.21 的命名路径。不同版本的源码行和报文措辞可以变化,选定目标中的 SQLSTATE 仍为 26000。
相关 {#related}
来源 {#sources}
src.errcodes.18.6(SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba)src.prepare.18.6(SHA-256e37fbd5f7618e5554561d9293d8c3af7cf3190c62c5c6bbceb3fe8b97be17956)src.postgres.18.6(SHA-2569fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061)PREPARE 官方文档· 本地调用扫描src.calls.REL_18_6(SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf)
比较版本
SQLSTATE 证据与已记录的运行版本
cases · prepared_statement_recovery
{
"assertions": [
"SQLSTATE is 26000",
"The prepared statement name is in the diagnostic",
"The same session can recreate and execute the statement after the error"
],
"case_id": "prepared_statement_recovery",
"cleanup": "Drop the case schema with an owner connection.",
"has_snippet": true,
"position": 0,
"preconditions": [
"A runner-owned disposable target is provisioned."
],
"repair": "Recreate the prepared statement on the session that will execute it; prepared statements are session-local.",
"trigger": "Prepare a named statement, deallocate it, then execute the missing name on the same session.",
"versions": [
"10",
"18"
]
}claims · identity
{
"claim_id": "identity",
"limits": "The definition does not identify which SQL statement resource is missing.",
"method": "Read the fixed errcodes.txt row and macro mapping.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "26000 is the invalid_sql_statement_name condition in Class 26."
}claims · server-path
{
"claim_id": "server-path",
"limits": "The name is dynamic; this source path is from REL_18_6.",
"method": "Trace ERRCODE_UNDEFINED_PSTATEMENT and errmsg in prepare.c.",
"position": 1,
"runtime": [],
"sources": [
"src.prepare.18.6",
"src.calls.REL_18_6"
],
"statement": "FetchPreparedStatement emits the source template prepared statement \"%s\" does not exist when a named prepared statement is absent."
}claims · unnamed-path
{
"claim_id": "unnamed-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.",
"method": "Trace ERRCODE_UNDEFINED_PSTATEMENT and errmsg in the fixed unnamed-statement protocol path.",
"position": 2,
"runtime": [],
"sources": [
"src.postgres.18.6",
"src.calls.REL_18_6"
],
"statement": "The fixed postgres.c extended-query path emits unnamed prepared statement does not exist with SQLSTATE 26000 when the unnamed prepared statement is absent."
}claims · session-scope
{
"claim_id": "session-scope",
"limits": "Connection pools can change backend sessions; this is a client/pool condition, not a promise about a particular driver.",
"method": "Use the fixed PREPARE/EXECUTE documentation and the runner case lifecycle.",
"position": 3,
"runtime": [],
"sources": [
"doc.prepare.18.6"
],
"statement": "PREPARE creates a session-local named statement; DEALLOCATE removes it, so EXECUTE must run on the same backend where the statement was created."
}claims · runtime
{
"claim_id": "runtime",
"limits": "This covers the selected mechanism only, not all source callers or all driver/pool behavior.",
"method": "Read the selected runner summaries and raw outputs tied to the shared snippet registry.",
"position": 4,
"runtime": [],
"sources": [
"runtime.26000-batch34-latest-20260909.latest",
"runtime.26000-batch34-pg10-20260909.pg10"
],
"statement": "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."
}messages · message.prepared-missing
{
"limits": "The unnamed prepared-statement path has a separate source template.",
"message_id": "message.prepared-missing",
"path": "",
"position": 0,
"raw": {
"id": "message.prepared-missing",
"limits": "The unnamed prepared-statement path has a separate source template.",
"primary_template": "prepared statement \"%s\" does not exist",
"severity_source": "ERROR",
"sources": [
"src.prepare.18.6"
],
"sqlstate": "26000"
},
"severity": "ERROR",
"sources": [
"src.prepare.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "prepared statement \" \" does not exist",
"position": 0,
"role": "",
"template": "prepared statement \"%s\" does not exist"
}
]
}messages · message.unnamed-prepared-missing
{
"limits": "This fixed protocol path has no server-side statement-name substitution.",
"message_id": "message.unnamed-prepared-missing",
"path": "",
"position": 1,
"raw": {
"id": "message.unnamed-prepared-missing",
"limits": "This fixed protocol path has no server-side statement-name substitution.",
"primary_template": "unnamed prepared statement does not exist",
"severity_source": "ERROR",
"sources": [
"src.postgres.18.6"
],
"sqlstate": "26000"
},
"severity": "ERROR",
"sources": [
"src.postgres.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "unnamed prepared statement does not exist",
"position": 0,
"role": "",
"template": "unnamed prepared statement does not exist"
}
]
}runtimes · runtime.26000-batch34-latest-20260909.latest · 18.6 (Homebrew) · passed
{
"cases": [
"prepared_statement_recovery"
],
"limits": "",
"position": 0,
"raw": {
"case_manifest": {
"path": "verify/cases/26000/cases.json",
"sha256": "8a93385404eaff2506cf2da0c35e4c079b0f2a5750445fd5f2bc42130b54a6ca"
},
"cases": [
"prepared_statement_recovery"
],
"id": "runtime.26000-batch34-latest-20260909.latest",
"observed": {
"connection_autocommit": true,
"primary": "prepared statement \"prepared_recovery_a347d8\" does not exist",
"repair": {
"values": {
"after_recreate": 2,
"before_deallocate": 2
}
},
"severity": "ERROR",
"sqlstate": "26000",
"statuses": {
"after_missing": "IDLE",
"after_recreate": "IDLE"
}
},
"raw": "verify/results/26000-batch34-latest-20260909/latest/raw.jsonl",
"raw_sha256": "abdac32a6667920c0106f2bbd141bf47bb2614a0477a4e6a4322de13242a44ef",
"run_id": "26000-batch34-latest-20260909",
"server_version": "18.6 (Homebrew)",
"snippet_registry": {
"path": "verify/cases/26000/snippets.json",
"sha256": "b9fdbb48371e0d9902cb9e055ececc4878c38422773a8a1571651d9952809032"
},
"status": "passed",
"summary": "verify/results/26000-batch34-latest-20260909/latest/summary.json",
"summary_sha256": "e6392b850858519b83a78884e27ba0e18c3f024b262549c1a63bc45648bc3265",
"target": "latest"
},
"run_id": "26000-batch34-latest-20260909",
"runtime_id": "runtime.26000-batch34-latest-20260909.latest",
"server_version": "18.6 (Homebrew)",
"status": "passed",
"target": "latest"
}runtimes · runtime.26000-batch34-pg10-20260909.pg10 · 10.21 (Debian 10.21-1.pgdg90+1) · passed
{
"cases": [
"prepared_statement_recovery"
],
"limits": "",
"position": 1,
"raw": {
"case_manifest": {
"path": "verify/cases/26000/cases.json",
"sha256": "8a93385404eaff2506cf2da0c35e4c079b0f2a5750445fd5f2bc42130b54a6ca"
},
"cases": [
"prepared_statement_recovery"
],
"id": "runtime.26000-batch34-pg10-20260909.pg10",
"observed": {
"connection_autocommit": true,
"primary": "prepared statement \"prepared_recovery_8e5c66\" does not exist",
"repair": {
"values": {
"after_recreate": 2,
"before_deallocate": 2
}
},
"severity": "ERROR",
"sqlstate": "26000",
"statuses": {
"after_missing": "IDLE",
"after_recreate": "IDLE"
}
},
"raw": "verify/results/26000-batch34-pg10-20260909/pg10/raw.jsonl",
"raw_sha256": "7dd35033652b224890790b92dffbfb00dce8f51e4e479fbfcd1590473b508f83",
"run_id": "26000-batch34-pg10-20260909",
"server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
"snippet_registry": {
"path": "verify/cases/26000/snippets.json",
"sha256": "b9fdbb48371e0d9902cb9e055ececc4878c38422773a8a1571651d9952809032"
},
"status": "passed",
"summary": "verify/results/26000-batch34-pg10-20260909/pg10/summary.json",
"summary_sha256": "ae189293998b2d4d288658165f9ee288a89baef4227910e5c9aaec09d3a42099",
"target": "pg10"
},
"run_id": "26000-batch34-pg10-20260909",
"runtime_id": "runtime.26000-batch34-pg10-20260909.pg10",
"server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
"status": "passed",
"target": "pg10"
}sources · src.errcodes.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt"
}sources · src.calls.REL_18_6
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_18_6.jsonl",
"position": 1,
"sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
"source_id": "src.calls.REL_18_6",
"tag": "",
"url": ""
}sources · src.prepare.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/commands/prepare.c",
"position": 2,
"sha256": "e37fbd5f7618e5554561d9293d8c3af7cf3190c62c5c6bbceb3fe8b97be17956",
"source_id": "src.prepare.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/prepare.c#L451-L454"
}sources · src.postgres.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/tcop/postgres.c",
"position": 3,
"sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
"source_id": "src.postgres.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L1670-L1672"
}sources · doc.prepare.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "https://www.postgresql.org/docs/18/sql-prepare.html",
"kind": "upstream_source",
"location": "",
"path": "doc/src/sgml/ref/prepare.sgml",
"position": 4,
"sha256": "0980f4925bdc3df25eaf4ca302b0ec43822731023a646aacebd8b01f69b2be71",
"source_id": "doc.prepare.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/doc/src/sgml/ref/prepare.sgml"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:4be0637eae94350c9aa59d1e1819e002e9d28460b3a6d3b9504e53d26c09959b
正文语言: zh-Hans · english-manuals:4be0637eae94350c9aa59d1e1819e002e9d28460b3a6d3b9504e53d26c09959b