update the entire object in the jsonb value psql code example

Example 1: update json in postgres

[{“type”: “phone”,value”: “+12025550105”}, {“type”: “email”,value”: “jimi.hendrix@gmail.com”}]

[{“type”: “email”,value”: “janis.joplin@gmail.com”}]

Example 2: postgresql update json field key value

UPDATE table_name SET attrs = jsonb_set(cast(attrs as jsonb), '{key}', '"new_value"', true) WHERE id = 'some_id';

Tags:

Sql Example