0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MySQLでネストされたjsonデータを更新する方法

Last updated at Posted at 2024-10-03

JSON_INSERT, JSON_REPLACE, JSON_SETを使い、ドット(.)でネストを指定できる

UPDATE table_name SET json_column = JSON_INSERT(json_column, "$.nestedField.Id", "value of id")

ちなみにbulk updateではこのように書ける

UPDATE table_name SET json_column = ELT(FIELD(id, 'id1', 'id2'), JSON_INSERT(json_column, '$.nestedField.Id', 'nestedFieldId1'), JSON_INSERT(json_column, '$.nestedField.Id', 'nestedFieldId2')) WHERE id IN ('id1', 'id2')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?