【发布时间】:2020-02-15 23:02:29
【问题描述】:
这是我使用 express 从我的 node.js 应用程序调用 postgres 的方式
const db_pg = require("./db-pg");
app.get('/pg/', (req,res,next) => {
db_pg.query(req).then((body) => {
res.send(body);
}).catch((err) => {
next(err);
})
});
在我的db-pg/index.js 文件中(不包括pool 设置的详细信息):
module.exports = {
query: (req) => {
return pool.query(req);
}
};
我从 postgreSQL 收到以下错误:
syntax error at or near ","
我要执行的查询是:
req = {
text: "SELECT * from my_func(?,?,?)",
values: ["the_name", 20190303, 20190620]
}
我的语法有什么问题?
【问题讨论】:
-
假设您使用的是 node-postgres,它看起来应该是
"SELECT * FROM my_func($1, $2, $3)": node-postgres.com/features/queries#parameterized-query
标签: node.js postgresql node-postgres