Get, add and remove JSON objects from an array. By Rob Tomlin.
CREATE INDEX idx_purchases_name
ON public.purchases
((items_purchased ->> 'name'));
In this article, author will work with a jsonb column containing an array of objects and explore how to:
- Get all objects in the array
- Get a specific object from the array by position in the array. When the position is known and when we have to discover it
- Add a json object to the array
- Remove a specific object from the array
- Indexing including indexing a key in the JSONB column
PostgreSQL has many functions and operators for JSON data. Links to further reading also provided in the article. Nice one!
[Read More]