节点postgres插入语法错误

问题描述:

我试图将我的psql安装切换到节点,并且无法获得以下测试查询的工作。节点postgres插入语法错误

PG = require('pg') 

module.exports = class Postgres extends Backbone.Model 
    initialize: => 
     PG.connect process.env.DATABASE_URL, (error, client) => 
      this.client = client 

      this.sendMessage(1, 2, '3') 


    sendMessage: (from, to, message) => 
     this.client.query('INSERT INTO messages(from, to, content) VALUES($1, $2, $3) RETURNING id', [from, to, message], (error, result) => 
      console.log 'error', error 
      console.log 'result', result 
     ) 

回应并出现以下错误:

error { [error: syntax error at or near "from"] 

我在做什么错?

我不知道它是否重要,但这是我的桌子。 enter image description here

+0

对不起,CoffeeScript的BTW。 –

+0

当然!男人,我是绝对最差的。谢谢阿德里亚诺 –

+0

将我的评论转换为答案,让人们更容易发现它。8月份的欢呼声! – AdrianoKF

我认为Postgres正在抱怨reserved keywordfrom作为列标识符。

你应该尝试双引号它在你的查询是这样的:

INSERT INTO messages("from", to, content) [...]