[英]How to INSERT INTO an array column of postgres using postman JSON?
I have a table with an array column myarray text[]
.我有一个带有数组列
myarray text[]
。 I have created an endpoint for inserting into array我创建了一个用于插入数组的端点
exports.createVaraus = async (id, myarray) =>$ try {
const result = await client.query('INSERT INTO mytable (id, myarray) VALUES ($1, $2) RETURNING id',
[id, myarray]
);
return result.rows[0]
} catch (err) {
throw new Error(err);
}
}
Now when I do POST with postman with following JSON:现在,当我使用以下 JSON 与邮递员进行 POST 时:
{
"id": 1,
"myarray": {"column1": "test"}
}
I get the following error:我收到以下错误:
"message": "error: malformed array literal: \\"{\\"column1\\":\\"test\\"}\\""
"message": "错误:格式错误的数组文字:\\"{\\"column1\\":\\"test\\"}\\""
What is wrong and how to do this properly?有什么问题以及如何正确执行此操作?
My table holds 2 columns: id and myarray.我的表包含 2 列:id 和 myarray。
I am using express.我正在使用快递。
My request body:我的请求正文:
exports.updateVaraus = async(request, response) => {
try {
let {id} = request.params;
const varausObject = request.body;
const updatedVaraus = await varausModel.updateVaraus(varausObject, id);
response.status(200).send(updatedVaraus);
} catch (err) {
response.status(400).send({message: err.message});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.