我正在尝试从客户端到服务器向PostQSL数据库中插入数据。但是,有一个错误,因为:
服务器错误:
uid: test id
gps: 111
(node:8607) UnhandledPromiseRejectionWarning: error: could not determine data type of parameter $2为什么不能将嵌套的JSON数据gps作为未知类型插入?
客户端(Angular):
tracking_info = {
uid: "test id",
gps: {
logitude: 111,
latitude: 222,
timestamp: 12345,
}
}
// Send data to server
api.post('savemessage', tracking_info).share();服务器(Node.js)
...
console.log("uid: "+ uid);
console.log("gps: "+ gps.latitude);
// insert a new message
await client.query('INSERT INTO messages(uid, gps) VALUES($1, $2)', [uid, gps])
...PostSQL表设置:
[Name] [DataType]
uid VARCHAR
gps UNKNOWN发布于 2018-08-29 15:33:45
使用JSON数据类型存储JSON数据。
CREATE TABLE tracking_info (
uid UUID NOT NULL,
gps JSON
);您可能需要执行JSON.stringify。
await client.query('INSERT INTO messages(uid, gps) VALUES($1, $2)', [uid, JSON.stringify(gps)])阅读以了解更多详细信息http://www.postgresqltutorial.com/postgresql-json/
https://stackoverflow.com/questions/52069944
复制相似问题