【发布时间】:2017-06-17 15:39:32
【问题描述】:
我在 postgres 中创建了一个名为 user 的表,其中包含 id, name, family 列(id 是自动递增的)。我想插入 postgres 的查询如下:
var config = {
user: 'username',
database: 'databaseName',
password: 'password',
host: 'localhost',
port: 5432,
max: 10,
idleTimeoutMillis: 30000
};
const pool = new postgre.Pool(config);
let query = "INSERT INTO user(name, family) VALUES ('name', 'family')";
pool.query(query, [], function (err, result) {
if (err) {
return console.error("error running query", err);
}
console.log("done!");
});
但是,我收到以下错误:
用户附近的语法错误
另外,我尝试了不同的方法来发送请求,如下所示:
const connectionString = "http://localhost:5432/databaseName?username=username&password=password";
const client = new postgre.Client(connectionString);
client.connect();
const query = client.query("INSERT INTO user(id, name, family) VALUES ('name', 'family')");
query.then(x => { console.log("done!")});
query.catch(x => { console.log(x)});
但我收到以下错误:
角色“用户名”不存在
另外,错误正文中的UserName(服务器名称)与数据库的username 不同。
我已经检查了所有可能的谬误,例如用户名和密码的正确性。
所以,问题是什么问题?
【问题讨论】:
标签: node.js postgresql