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 + '')
相关推荐
喂自己代言12 小时前
常见的关系型数据库有哪些?如何安装和使用Postgres?(中英双语版)
sql·postgresql·database
u***32431 天前
使用python进行PostgreSQL 数据库连接
数据库·python·postgresql
V***u4531 天前
如何查看PostgreSQL的版本
数据库·postgresql
9***J6281 天前
Linux下PostgreSQL-12.0安装部署详细步骤
linux·运维·postgresql
IvorySQL1 天前
PostgreSQL 18 - 时间约束 (Temporal Constraints)
数据库·postgresql·开源
q***61411 天前
从MySQL迁移到PostgreSQL的完整指南
数据库·mysql·postgresql
东南门吹雪1 天前
PostgreSQL与MySQL的锁与隔离级别
mysql·postgresql·区块链
q***65692 天前
PostgreSQL 中进行数据导入和导出
大数据·数据库·postgresql
q***44812 天前
postgresql链接详解
数据库·postgresql
2301_800256112 天前
第七章 空间存储与索引 知识点梳理3(空间填充曲线)
数据库·笔记·sql·postgresql