"error: bind message supplies 1 parameters, but prepared statement " " requires 0"不确定这背后的含义或如何解决它



我正在上数据库课,并在尝试运行程序时收到该错误。

const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.set("port", 8080);
app.use(bodyParser.json({ type: "application/json" }));
app.use(bodyParser.urlencoded({ extended: true }));
const Pool = require("pg").Pool;
const config = {
host: "localhost",
user: "me",
password: "64594640",
database: "new"
};
const pool = new Pool(config);
//say hello
app.get("/hello", (req,res) => {
res.json("Hello world!");
});
app.get("/workshop", async (req,res) => {
try {
// find workshops
const template = "SELECT workshop FROM people";
const responce = await pool.query(template, [req.query.q]);
console.log(response);
} catch (err) {
console.log("whoops " + err);
}
});
app.listen(app.get("port"), () => {
console.log(`Find the server at: http://localhost:${app.get("port")}/`);
});

我正在节点上运行该程序,并且有一个新的 postgresql 数据库,所有者是我的。

您已经为query方法提供了一个参数:

req.query.q

因此,该方法会搜索将此参数放入SELECT workshop FROM people查询的位置。

它找不到要替换为参数req.query.q的占位符$1。 您要么忘记在查询中放置一些参数,要么不需要向其传递任何参数。

若要查看有关query参数方法的详细信息,请参阅示例: https://node-postgres.com/features/queries#Parameterized%20query

最新更新