gpt4 book ai didi

mysql - 如何在JSON列中的mysql中的现有JSON内插入JSON?

转载 作者:行者123 更新时间:2023-11-29 16:24:04 25 4
gpt4 key购买 nike

我想通过数据库查询在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com