postgresqlHow can I use jsonb_set to update a PostgreSQL database?
JSONB_SET is a PostgreSQL function used to update fields in a JSONB column. It allows for the insertion of new values, as well as the replacement of existing values.
Example
UPDATE my_table
SET my_jsonb_column = jsonb_set(my_jsonb_column, '{name}', '"John"')
WHERE id = 1;
The above example will update the my_jsonb_column in my_table with the id of 1 and set the name field in the JSONB column to John.
Code explanation
UPDATE my_table- This is used to indicate which table we are updating.SET my_jsonb_column = jsonb_set(my_jsonb_column, '{name}', '"John"')- This is used to set themy_jsonb_columnto the return value ofjsonb_setwith thenamefield and the valueJohn.WHERE id = 1- This is used to indicate which record we are updating.
Helpful links
More of Postgresql
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I use PostgreSQL with Zabbix?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL and ZFS together?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I extract the year from a PostgreSQL timestamp?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL XML functions to manipulate XML data?
- How can I integrate PostgreSQL with Yii2?
See more codes...