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 + '')
相关推荐
IvorySQL1 天前
云环境下PostgreSQL的Cgroup内存管理实践
java·数据库·postgresql
IvorySQL2 天前
PG 日报|SQL/PGQ 图查询基于联接重写机制实现
数据库·人工智能·sql·postgresql·区块链·ivorysql
IvorySQL2 天前
深度拆解 IvorySQL 去 O 核心解决方案
数据库·人工智能·postgresql
大猫会长2 天前
mac安装PostgreSQL18笔记
postgresql
IvorySQL3 天前
PG 日报|新增 VACUUM 全维度统计信息补丁迭代
数据库·人工智能·postgresql·ivorysql
运维老郭3 天前
PostgreSQL编译安装实战
运维·postgresql
l1t3 天前
DeepSeek总结的RegreSQL 2.0测试通过了。计划却没通过。
linux·数据库·postgresql
ls_elect3 天前
PostgreSQL 18.4 SCRAM-SHA-256 认证故障诊断及修复办法
linux·数据库·postgresql
IvorySQL4 天前
PG 日报|社区讨论重构 pg_hba 配置文件格式
数据库·人工智能·postgresql·重构·ivorysql
weixin_307779134 天前
Linux下Docker Compose里运行PostgreSQL数据库故障诊断Shell脚本
linux·运维·数据库·docker·postgresql