Skip to Main Content

How should the query be formed using JSON to yield the following result (MySQL v8.0.21)?

bevansoundFeb 21 2021

HI! I have this JSON block
[
{
"RGTs": ["rgt_a"],
"id": "289",
"name": "Group1"
},
{
"RGTs": [
"rgt_b",
"rgt_c",
"rgt_d"
],
"id": "949",
"name": "Group2"
},
{
"RGTs": ["rgt_e"],
"id": "621",
"name": "Group3"
}
]

I want to INSERT rgt_f and rgt_g INTO the RGTs array WHERE id = 949
Meaning, append the second element's RGTs array.

So the resultant JSON would look like this

[
{
"RGTs": ["rgt_a"],
"id": "289",
"name": "Group1"
},
{
"RGTs": [
"rgt_b",
"rgt_c",
"rgt_d",
"rgt_f",
"rgt_g"
],
"id": "949",
"name": "Group2"
},
{
"RGTs": ["rgt_e"],
"id": "621",
"name": "Group3"
}
]

What MySQL JSON functions would I use to make this work?

Comments
Post Details
Added on Feb 21 2021
1 comment
19 views