2015-07-22 97 views
1

我試圖將我的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

回答

2

我認爲Postgres正在抱怨reserved keywordfrom作爲列標識符。

你應該嘗試雙引號它在你的查詢是這樣的:

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