0
notice
[
 {
   "date": "2022. 10. 16.", 
   "type": 3, 
   "title": "friend", 
   "content": "JJ friend", 
   "parameter": "test"
 }, 
 {
   "date": "2022. 10. 16.", 
   "type": 3, 
   "title": "friend", 
   "content": "testtest friend", 
   "parameter": "test1"
  }
]

I wanna search and remove in json {"date": "2022. 10. 16.","type": 3,"title": "friend","content": "testtest friend","parameter": "test1"} where id = 'test2'

There's a separate column for the ID.

update UserTable set notice = json_remove(notice, json_search(notice, 'one', 
'{"date": "2022. 10. 16.","type": 3,"title": "friend","content": "testtest friend","parameter": "test1"}')) where id = 'test2'";
JiNyeok_S
  • 3
  • 2
  • How do you uniquely identify the json object you want to remove from the array you have? – lemon Oct 16 '22 at 16:34
  • I don't have a unique ID that I can identify, but I want it to be deleted if the contents of json are the same. – JiNyeok_S Oct 16 '22 at 20:02

1 Answers1

2
SELECT JSON_ARRAYAGG(jsonvalue)
FROM src_table
CROSS JOIN JSON_TABLE(src_table.notice,
                      '$[*]' COLUMNS (jsonvalue JSON PATH '$')) jsontable
WHERE jsonvalue <> CAST('{"date": "2022. 10. 16.","type": 3,"title": "friend","content": "testtest friend","parameter": "test1"}' AS JSON)
Akina
  • 39,301
  • 5
  • 14
  • 25