【问题标题】:Node.js INSERT into postgres errorNode.js INSERT 到 postgres 错误
【发布时间】:2023-03-07 17:01:01
【问题描述】:

我有以下 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"
}

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

【问题讨论】:

    标签: node.js postgresql


    【解决方案1】:

    您的查询中有INSER 而不是INSERT

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 2017-02-14
    • 1970-01-01
    • 2014-07-02
    相关资源
    最近更新 更多