I have an existing table like that:
id | json
---+----------
1 | {"1":"1"}
2 | NULL
and i want to be able to merge {"2":"2"} into any one of the existing rows wheater or not the json field already contains JSON or is NULL.
That it looks like that:
id | json
---+----------
1 | {"1":"1", "2":"2"}
2 | {"2":"2"}
with UPDATE table SET json = CAST('{"2":"2"}' AS JSON) WHERE id=1) I can only update the second row or overwrite the first one.
with UPDATE table SET json = JSON_MERGE(json, CAST('{"2":"2"}' AS JSON) WHERE id=1) I can only update the first row, the second row stays unchanged.
Is there a single command that accounts for both cases?