You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Sequelize调用PostgreSQL存储过程时含单引号字符串引发500错误

问题:Sequelize调用PostgreSQL存储过程遇含单引号字段报错?

代码与报错信息

我尝试通过Sequelize调用PostgreSQL存储过程,代码如下:

const reqObj = JSON.stringify({
  'id': 54,
  'name': 'my_key',
  'note': "the driver's position"
});

const results = await sequelize.query(
  `call app.my_procedure(:reqObj, 0)`, 
  { 
    raw: true,
    replacements: { reqObj }, 
    type: QueryTypes.SELECT, logging: console.log }
);

其中note字段包含单引号,运行后触发500错误,错误信息:

invalid input syntax for type numeric: "syntax error at or near "position""

查看执行日志,单引号已被正确转义:

Executing (default): call app.my_procedure('{"id":"54","name":"my_key", "note":"the driver''s position"}', 0)

问题排查结果

经过确认,问题并非出在Sequelize的调用代码上,而是存储过程本身存在bug。


内容的提问来源于stack exchange,提问作者Short Circuit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 17:07:44