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 + '')
相关推荐
ycjunhua13 小时前
windows 安装PostgreSQL 数据库
数据库·windows·postgresql
Mr.徐大人ゞ13 小时前
2-6.pg特性功能之系列规则介绍和使用
postgresql
NotFound4861 天前
分享实战心得PostgreSQL 主从复制:告别单点故障,附主从切换与延迟监控命令
数据库·postgresql
Pluto_CSND1 天前
PostgreSQL 聚合函数总览
数据库·postgresql
石工记2 天前
postgresql18 安装-运行
数据库·postgresql
csdn2015_2 天前
postgresql string_to_array 方法
数据库·postgresql
编程经验分享2 天前
Windows 安装 PostgreSQL 并安装 vector 扩展
数据库·postgresql
韩楚风2 天前
PostgreSQL入门与进阶学习,体系化的SQL知识,完成终极目标高可用与容灾,性能优化与架构设计,以及安全策略
sql·学习·postgresql
Edward Nygma3 天前
zyy~P0 【OKR】智能解读组件专项-看板解读接算法
postgresql
Edward Nygma3 天前
zyy~P0 潜客探查专项-潜客探查优化
postgresql