PgSQL报错“绑定消息提供了1个参数,但是已准备好语句““ 要求0个参数“

报错现象:

bash 复制代码
error: 绑定消息提供了1个参数,但是已准备好语句"" 要求0个参数
    at Parser.parseErrorMessage (file:///C:/Work/@ruoyi/RuoYi-Api/dist/chunks/pg-e4b34908.js:2959:98)
    at Parser.handlePacket (file:///C:/Work/@ruoyi/RuoYi-Api/dist/chunks/pg-e4b34908.js:2798:29)
    at Parser.parse (file:///C:/Work/@ruoyi/RuoYi-Api/dist/chunks/pg-e4b34908.js:2711:38)
    at Socket.<anonymous> (file:///C:/Work/@ruoyi/RuoYi-Api/dist/chunks/pg-e4b34908.js:2991:43)
    at Socket.emit (node:events:518:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 141,
  severity: '错误',
  code: '08P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'postgres.c',
  line: '1720',
  routine: 'exec_bind_message'
}

错误原因:

bash 复制代码
  wheres.push(`'$${params.length + 1}' = ANY(string_to_array(ancestors, ','))`)
  params.push(deptId)

deptId是整数型,需要转成字符串型参与和ANY函数的匹配,但是deptId转字符串不应该在wheres的模板中加单引号'进行,而是在params中转成字符串型后,让pgsql去替换,正确的是

bash 复制代码
  wheres.push(`$${params.length + 1} = ANY(string_to_array(ancestors, ','))`)
  params.push(deptId + '')
相关推荐
xuefuhe2 分钟前
PostgreSQL Page Layout
postgresql
云贝贝贝1 小时前
PostgreSQL 生产环境备份恢复与高可用实战
数据库·postgresql
wangchunyu1146 小时前
PostgreSQL 入门与实践:从零搭建一个 CRUD 应用
数据库·postgresql
m0_5791466513 小时前
PostgreSQL+Milvus分层存储架构:双写一致性与CAP理论取舍分析
postgresql·架构·milvus·cap
瀚高PG实验室13 小时前
PostgreSQL CREATE TYPE 未检查 multirange schema 的 CREATE 权限HGVE-2026-E007
数据库·postgresql·瀚高数据库
夏炳辉.13 小时前
零基础Linux PostgreSQL(psql)从安装到集群高可用全套学习大纲
linux·学习·postgresql
像风一样自由202014 小时前
15.Milvus是什么?为什么RAG系统经常使用它?
postgresql·大模型·milvus·rag·智能体
瀚高PG实验室1 天前
PostgreSQL pg_basebackup 和 pg_rewind 可覆盖源端超级用户选择的无关文件HGVE-2026-E010
数据库·postgresql·瀚高数据库
张文君1 天前
ubuntu26.04从ext4改成raid1+lvm启动
数据库·postgresql