I am working with an existing table, where the column is of type JSONB. The data looks like this:
{ key1: {...}, key2: {...}}I would like to migrate all the existing data in this DB so that this JSONB data looks like this instead:
[{ key1: {...}, key2: {...}}]I want the existing object to be wrapped in an array.
I think I might be able to usejsonb_build_array, but I'm not completely sure.
Has anyone had to do this before?
1 Answer1
Yes, jsonb_build_array() is the right approach:
update the_table set the_column = jsonb_build_array(the_column); answeredAug 15, 2022 at 15:02
user330315
Sign up to request clarification or add additional context in comments.
2 Comments
thehme
Great! Can this be easily reverted? I didn't see a way to undo this update, if needed.
Explore related questions
See similar questions with these tags.