Forum Stats

  • 3,726,738 Users
  • 2,245,248 Discussions
  • 7,852,382 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

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?

Sign In or Register to comment.