VuNguyen
05/02/2022, 2:29 PMVuNguyen
05/02/2022, 2:29 PMjson
{
"native":"镇魂街",
"romaji":"Zhen Hun Jie",
"english":null,
"userPreferred":"Zhen Hun Jie"
}
now I want to add a new property to it, it should be
json
{
"native":"镇魂街",
"romaji":"Zhen Hun Jie",
"english":null,
"userPreferred":"Zhen Hun Jie",
"vietnamese": "Trấn Hồn Nhai 2"
}
This is what I've tried so far, it worked with one row, but when I try to run it on all rows, it return this error
invalid input syntax for type json
ps
UPDATE kaguya_anime
SET title = title::JSONB || concat('{"vietnamese":"', "vietnameseTitle", '"}')::JSONB
WHERE "vietnameseTitle" IS NOT NULL
garyaustin
05/02/2022, 3:23 PMVuNguyen
05/02/2022, 3:30 PMVuNguyen
05/02/2022, 3:31 PMps
UPDATE kaguya_anime
SET title = title::JSONB || jsonb_set(title::JSONB, '{vietnamese}', to_jsonb("vietnameseTitle"))
WHERE "vietnameseTitle" IS NOT NULL
VuNguyen
05/02/2022, 3:31 PMjsonb_set
and luckily it worked