使用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
相关产品推荐
相关产品推荐

