0

我正在尝试使用以下函数在 node-postgres (pg) 中执行连接查询,但出现语法错误。问题是连接查询,其他一切正常。在 pg 中格式化连接查询的正确方法是什么?

exports.bigBook = function(req, res) {
  var bookNumber = req.params.id;
  pool.connect(function(err, client, done) {
   if (err) { return console.error('error fetching client from pool', err);}
   client.query('SELECT * FROM book WHERE id = $1 LEFT JOIN author 
    ON (book.author = author.auth_id)'), [bookNumber], function (err, results) {
    client.release();
    res.send(results.rows);
  };
 })
}
4

1 回答 1

1

LEFT JOIN是子句的一部分FROM,因此您必须将WHERE子句移到查询的末尾。

于 2016-10-26T18:18:58.453 回答