cit*_*vin 1 postgresql node.js node-postgres
正如标题所示,我在使用时遇到语法错误node-postgres。代码如下所示
const {Pool, Client} = require('pg')
const pool = new Pool({
user: '<user>',
host: '<host>',
database: '<database>',
password: '<pw>',
port: <port>
})
let query = `SELECT * FROM user JOIN notifications ON user.user_id = notifications.user_id WHERE user_id=$1`
let values = ["123"]
pool.query(query, values)
.then(() => { /* do something */} )
.catch((err) => { console.log(err)} )
Run Code Online (Sandbox Code Playgroud)
根据此查询,我收到以下消息的语法错误
syntax error at or near "."
Run Code Online (Sandbox Code Playgroud)
由于相同的查询在 pgAdmin 中运行良好,我的猜测是它是特定于模块的,但我还没有弄清楚问题是什么。
非常感谢任何帮助!
编辑:添加了缺失的括号,感谢 Sreeragh AR
user是 postgresql 中的保留字,必须user使用双引号转义
let query = `SELECT * FROM "user" JOIN notifications ON "user".user_id = notifications.user_id WHERE "user".user_id=$1`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6432 次 |
| 最近记录: |