选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 42 语法错误或访问规则冲突

42P05 duplicate_prepared_statement

重复预备语句

ERROR 源码确认 详解 未实测

条件名
duplicate_prepared_statement
宏名称
ERRCODE_DUPLICATE_PSTATEMENT
启用版本
7.4
状态
活跃

版本覆盖

速览

42P05duplicate_prepared_statement)表示当前后端/会话已有同名服务器端预备语句。连接池可能让后续请求复用这段状态,而另一条连接可以拥有同名的独立语句。

含义

StorePreparedStatement 把命名语句放在当前后端的 prepared_queries 哈希表中;HASH_ENTER 发现名称已存在时,在保存新计划前报告 ERROR prepared statement "%s" already existsDEALLOCATE name 删除当前后端的一项,DEALLOCATE ALL 删除当前后端的全部项;它们不会删除另一条连接拥有的语句。

诊断

检查物理连接/后端身份、pg_prepared_statements、连接池签出历史和 PREPARE 路径,区分命名服务器语句、未命名协议语句和驱动本地缓存键。若多个请求复用了同一连接,先核对准确名称和参数类型再修改 SQL。

处理

只有 SQL 与参数类型匹配时才复用现有语句;否则由该连接的所有者协调 DEALLOCATE name、使用确定性的唯一名称,或按连接池生命周期策略重置会话。不要在另一条连接执行 DEALLOCATE 后假定冲突已清除。此 ERROR 若发生在显式事务中,应回滚保存点或回滚事务;重连只是受控重置,不是通用修复。

消息变体

确认的 18.6 变体是 ERRORprepared statement "%s" already exists%s 是动态的服务器端名称。

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 prepared statement "%s" already exists

来源:src/backend/commands/prepare.c(lines 412-415) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

版本

目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的 18.6 源码覆盖当前后端的插入与释放路径,未运行数据库。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 42P05 is the duplicate_prepared_statement condition in Class 42.

    核实方式Read fixed REL_18_6 errcodes.txt and locked facts.

    不覆盖Identity does not enumerate all source branches or client failures.

    来源src/backend/utils/errcodes.txt(line 381)

  • StorePreparedStatement inserts named statements into the current backend's prepared_queries hash and reports ERROR `prepared statement "%s" already exists` when HASH_ENTER finds the name. DEALLOCATE removes entries from that backend's hash; another connection has independent state.

    核实方式Read complete resolved REL_18_6 report groups and message roles.

    不覆盖Representative confirmed core paths only; not exhaustive historical or extension coverage.

    来源src/backend/commands/prepare.c(lines 412-415) · src/backend/commands/prepare.c(lines 401-423 and 504-511)

  • From 7.4 through 18.6 and 19beta3; this catalogue range is not a precise introduction claim. The selected 18.6 source covers insertion and current-backend deallocation, and runtime was not run.

    核实方式Read locked catalogue facts and definition snapshots.

    不覆盖First observed release is a lower bound, not precise behavioral introduction.

    来源src/backend/utils/errcodes.txt(line 381)

同类错误代码

Class 42 语法错误或访问规则冲突 下的其他成员。