Requirements Description :
Insert a value into the JSON field through Json_insert, where you experiment and record.
Operation Process :
1. View existing tables that contain JSON data types
Mysql> Select * fromTab_json;+----+------------------------------------------------------------------------------------------------+|Id|Data|+----+------------------------------------------------------------------------------------------------+| 1 |{"Age": " -"," tel ":13249872314, "name": "Mike", "Address": "Shenzhen", "passcode": "654567"}|| 2 |{"Age": " -"," tel ":189776542, "name": "David", "Olds": " A"," Address ":" Hangzhou "}|+----+------------------------------------------------------------------------------------------------+2Rowsinch Set(0.00Sec
2. Inserting values by Json_insert
Mysql> UpdateTab_json Set data = Json_insert(Data, "$.age", " A")whereId= 1; #对一个已经存在的key进行操作, the value does not change Query OK,0Rows Affected (0.00sec) Rows matched:1Changed:0Warnings:0MySQL> Select * fromTab_json;+----+------------------------------------------------------------------------------------------------+|Id|Data|+----+------------------------------------------------------------------------------------------------+| 1 |{"Age": " -"," tel ":13249872314, "name": "Mike", "Address": "Shenzhen", "passcode": "654567"}|| 2 |{"Age": " -"," tel ":189776542, "name": "David", "Olds": " A"," Address ":" Hangzhou "}|+----+------------------------------------------------------------------------------------------------+2Rowsinch Set(0.00sec) MySQL> UpdateTab_jsonSetData=Json_insert (data, "$.") CARD ","1989833333")whereId= 1; #对不存在的key进行操作, the result is an increased key-value value Query OK,1Row affected (0.01sec) Rows matched:1Changed:1Warnings:0MySQL> Select * fromTab_json;+----+-------------------------------------------------------------------------------------------------------- --------------+|Id|Data|+----+-------------------------------------------------------------------------------------------------------- --------------+| 1 |{"Age": " -"," tel ":13249872314, "CARD": "1989833333"," name ":" Mike "," Address ":" Shenzhen "," passcode ":"654567"}|| 2 |{"Age": " -"," tel ":189776542, "name": "David", "Olds": " A"," Address ":" Hangzhou "}|+----+-------------------------------------------------------------------------------------------------------- --------------+2Rowsinch Set(0.00Sec
Note: So the function of Json_insert is inserting, inserting non-existent key-value pairs, if the operation is not changed for an existing key
Document creation Time: June 5, 2018 22:06:43
In MySQL, insert a key value into the JSON field via the Json_insert function? Use of the Json_insert function?