Answer the question
In order to leave comments, you need to log in
How can I update (add data) a JSON field?
We have a field in the table
`names` JSON NULL DEFAULT NULL,
I'm trying to update it
DB::table('towns')
->where('id', $town['id'])
->update([
'names' => "JSON_MERGE_PATCH(`names`, JSON_OBJECT('$timestamp', '$name'))"
]);
SQLSTATE[22032]: <<Unknown error>>: 3140 Invalid JSON text: "Invalid value."
at position 0 in value for column 'towns.names'.
(SQL: update `towns` set `names` = JSON_MERGE_PATCH(`names`, JSON_OBJECT('1599001255', 'Кэрг')) where `id` = 1225)
UPDATE `towns`
SET
`names` = JSON_MERGE_PATCH(`names`, JSON_OBJECT('1599001255', 'Кэрг'))
WHERE `id` = 1225
Answer the question
In order to leave comments, you need to log in
Decision:
DB::table('towns')
->where('id', $town['id'])
->update([
'names' => DB::raw("JSON_MERGE_PATCH(`names`, JSON_OBJECT('$timestamp', '$name'))")
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question