在我的nodejs应用程序中,运行以下代码行:
return models.sequelize.query("INSERT INTO \"DelegateUserLinks\" VALUES
(" + id + "," + _user.id + ", '2019-01-10 13:06:41.920', '2019-01-10
13:06:41.920')", function(err){
return Promise.reject(err);
});
这失败。我真的不明白为什么。读取错误日志,错误代码为22P02
。
据我了解,错误代码表示将数据类型转换为整数时失败。
但是我看不到我有这个问题(查看查询)。查询本身(打印在错误日志中)在我看来似乎还可以:
INSERT INTO \"DelegateUserLinks\" VALUES (10,677, '2019-01-10 13:06:41.920', '2019-01-10 13:06:41.920')"
如果问题是从数据类型转换为整数,我看到数字10
和677
在查询中被写为纯整数。那么真正的问题是什么?我还对日期进行硬编码,以确保问题不存在。这是完整的错误日志:
{"name":"SequelizeDatabaseError","parent":{"name":"error","length":117,"severity":"ERROR","code":"22P02","position":"49","file":"numutils.c","line":"104","routine":"pg_atoi","sql":"INSERT INTO \"DelegateUserLinks\" VALUES (10,677, '2019-01-10 13:06:41.920', '2019-01-10 13:06:41.920')"},"original":{"name":"error","length":117,"severity":"ERROR","code":"22P02","position":"49","file":"numutils.c","line":"104","routine":"pg_atoi","sql":"INSERT INTO \"DelegateUserLinks\" VALUES (10,677, '2019-01-10 13:06:41.920', '2019-01-10 13:06:41.920')"},"sql":"INSERT INTO \"DelegateUserLinks\" VALUES (10,677, '2019-01-10 13:06:41.920', '2019-01-10 13:06:41.920')","error@context":{}}