我想通过数据库查询在MySQL中的现有JSON数据内插入JSON数据。另外,如果JSON字段已经存在,则它不应执行任何操作。
例如,我的jsonTable分别具有id和jsonConfig列,并且JSON字段包含某些id的数据,如下所示。
{
"name": "Baljinder",
"siblings": {
"name": "Sukhjinder",
"age": 29,
"alive": true
}
}
现在,我想在兄弟姐妹的对象内插入下面给出的地址JSON对象。
"address": {
"city": "Melbourne",
"country": "Australia"
}
这样我的最终结果就是这样。
{
"name": "Baljinder",
"siblings": {
"name": "Sukhjinder",
"age": 29,
"alive": true,
"address": {
"city": "Melbourne",
"country": "Australia"
}
}
}
最佳答案
我试过了,这在MySQL 5.7.13上对我有用
UPDATE jsonTable SET jsonConfig=JSON_INSERT(jsonConfig, "$.siblings.address", JSON_OBJECT('city','Melbourne','country','Australia')) where id = <?>;
关于mysql - 如何在JSON列中的mysql中的现有JSON内插入JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54359559/