Node.js INSERT到postgres错误

时间:2013-12-18 23:16:59

标签: node.js postgresql

我有以下node.js + express代码,它将数据插入postgres。

app.post('/register', function(request, response) {
    pg.connect(connString, function(err, client, done) {
        if(err) response.send("Could not connect to DB: " + err);
        client.query('INSER INTO clients (client_id, params) VALUES ($1, $2)',
            [request.query.client_id, request.query.params], 
            function(err, result) {
                done();
                if(err) return response.send(err);
                response.send('OK');
        });
    });
});

表结构是:

CREATE TABLE clients
(
client_id character varying NOT NULL,
params character varying[] NOT NULL,
id integer NOT NULL DEFAULT nextval('clients_id_seq1'::regclass),
CONSTRAINT clients_pkey PRIMARY KEY (id)
)

如果我做一个普通的SELECT,它运作良好。但是在INSERT上我得到了这个HTTP 200响应:

{
 "name": "error",
 "length": 86,
 "severity": "ERROR",
 "code": "42601",
 "position": "1",
 "file": "scan.l",
 "line": "1044",
 "routine": "scanner_yyerror"
}

这个错误并没有对我说太多。

1 个答案:

答案 0 :(得分:2)

您的查询中有INSER而不是INSERT