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 + '')
相关推荐
秉承初心10 天前
PostgreSQL 数据性能瓶颈突破实战
数据库·postgresql·oracle
IvorySQL10 天前
PostgreSQL 技术日报 (6月15日)|PG19 性能优化推进,POSETTE 大会倒计时 2 天
数据库·人工智能·postgresql·开源
IvorySQL10 天前
PostgreSQL 技术日报 (6月16日)|Neon 自动化再进一步,逻辑复制冲突日志迎来 v50 更新
数据库·postgresql·自动化
倒流时光三十年10 天前
PostgreSQL 聊一下索引和排序规则
postgresql
睡不醒男孩03082311 天前
PostgreSQL 数据库运维转型:从传统模式到 CLup 平台的 25 个核心 FAQ
运维·数据库·postgresql
JOJO数据科学11 天前
pgAdmin4 Electron 鸿蒙 PC 适配全记录:从白屏到连接 PostgreSQL
postgresql·electron·harmonyos
日取其半万世不竭11 天前
PostgreSQL 跑在 Docker 里怎么备份?恢复成功才算备份成功
数据库·docker·postgresql
倒流时光三十年11 天前
PostgreSQL LEAST 表达式函数详解
数据库·postgresql
Rain50911 天前
2.4. PostgreSQL 数据库连接与实战指南
前端·数据库·人工智能·后端·postgresql·数据分析
倒流时光三十年12 天前
PostgreSQL CASE 条件表达式详解
数据库·postgresql