NodeJS + pg插件 - 错误:语法错误或接近»SET«

时间:2014-12-25 19:45:50

标签: javascript node.js postgresql pg

我正在使用nodeJS和pg plugin

我想在我的数据库中插入一些数据,但是,我收到错误:

[Function]
error running query { [error: syntax error at or near »SET«]
  name: 'error',
  length: 81,
  severity: 'FEHLER',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '20',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  file: 'scan.l',
  line: '1001',
  routine: 'scanner_yyerror' }

这是我的代码

var pg = require('pg');
var Pusher = require('pusher-client');
var conString = "postgres://admin:admin@localhost/testDB";

//connect to pusher API
var API_KEY = '1adfsdgf123edas';
var pusher = new Pusher(API_KEY, {
    encrypted: true
}); 

/**
 * connect to postgresql db and insert pusher results into db
 */
pg.connect(conString, function(err, client, done) {
    if(err) {
        return console.error('error fetching client from pool', err);
    }

    var channel = pusher.subscribe("test.160");
    channel.bind("message", function(data) {
//      console.log(data);

        /**
         * select which data to save to db
         */
        var prod  = {exchange       : 'test.com', 
                market_id           : 'test.160', 
                typeOfTransaction   : 'buy', 
                timestamp           : data.timestamp,
                price               : data.topbuy.price, 
                quantity            : data.topbuy.quantity, 
                created_at          : data.datetime  
        };

        //send query to db
        client.query('INSERT INTO prods SET ?', prod, function(err, result) {
            //call `done()` to release the client back to the pool
            done();

            if(err) {
                return console.error('error running query', err);
            }
            console.log(result.rows[0].number);
            //output: 1
    });

为什么我的代码在postgresql下不起作用的任何建议?

感谢您的回复!

0 个答案:

没有答案