正如标题所述,我在使用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)} )
基于此查询,我收到消息语法错误
syntax error at or near "."
由于同一查询在pgAdmin中可以正常运行,所以我猜想它是特定于模块的,但是我还没有弄清楚问题出在什么地方。
任何帮助,不胜感激!
编辑:感谢Sreeragh A R
,添加了缺少的括号答案 0 :(得分:3)
user
是Postgresql中的保留字,您必须使用双引号将user
转义
let query = `SELECT * FROM "user" JOIN notifications ON "user".user_id = notifications.user_id WHERE "user".user_id=$1`