How on earth do I insert data into a json mysql field.
I can create a record
INSERT INTO git_object (user_id,git_meta,last_update) VALUES ('11111','[{"host": "a", "id": "1"}]',(select now()));
How do I append to the array.
SELECT JSON_ARRAY_APPEND(git_meta, '$', '{"host": "b"}') FROM git_object where user_id='11111'
I tried the above. What do I get with the below?
SELECT * FROM git_object;
'[{"id": "1", "host": "a"}]'
What am I doing wrong
MySQL Version '5.7.13'
To modify data stored in any table you need to use the update
sql command, not select.
Update git_object
set git_meta=JSON_ARRAY_APPEND(git_meta, '$', '{"host": "b"}')
where user_id='11111'
Use JSON_ARRAY_APPEND(git_meta, '$', JSON_OBJECT('host','b'))
instead of JSON_ARRAY_APPEND(git_meta, '$', '{"host": "b"}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With