postgres jsonb array push new element 1

postgres jsonb array push new element

UPDATE jsontesting
SET jsondata = jsondata || '["newString"]'::jsonb
WHERE id = 7;

Here is what the above code is Doing:
1. We’re selecting the row with id = 7
2. We’re converting the jsondata column to text
3. We’re adding the new string to the end of the text
4. We’re converting the text back to jsonb
5. We’re updating the row with the new jsonb data

Similar Posts