Reputation: 4976
I'm trying to switch my psql setup over to node, and can't get the following test query to work.
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
)
Responds with the following error:
error { [error: syntax error at or near "from"]
What am I doing wrong?
I don't know if it matters, but here's my table.
Upvotes: 1
Views: 877
Reputation: 3021
I think Postgres is complaining about the reserved keyword from
as a column identifier.
You should try double-quoting it in your query like this:
INSERT INTO messages("from", to, content) [...]
Upvotes: 2