Manipulating JSONB Fields to Add or Remove Attributes
Use the || operator to add attributes and the - operator to remove them from JSONB fields in SQL queries.
Adding Attributes
SELECT
a.metadata || ('{"DVD": "ROM"}') AS metadata_new_attribute,
a.*
FROM audit a;Removing Attributes
SELECT
a.metadata - 'amount' AS metadata_without_amount,
a.*
FROM audit a;PreviousUse of the IN vs. = Clause for a Single ValueNextManipulating JSONB with jsonb_each_text() to Expand Fields
Last updated