Create a table with json type column
Now let's insert the JSON data
# INSERT INTO friends(data) VALUES ('{"name": "Arya", "work": ["Improvements", "Office"], "available": true}'); # INSERT INTO friends(data) VALUES ('{"name": "Tim Cook", "work": ["Cook", "ceo", "Play"], "uses": ["baseball", "laptop"], "available": false}');
Now let's make some queries to retrieve the data
# select data->'name' from friends;
You may have noticed that the results come with quotation marks (") and brackets ([])
name | work ------------+---------------------------- "Arya" | ["Improvements", "Office"] "Tim Cook" | ["Cook", "ceo", "Play"] (2 rows)
Now to retrieve only values ββjust use ->>
# select data->>'name' as name, data->'work'->>0 as work from friends;
Sandip Debnath Aug 30 '18 at 14:04 2018-08-30 14:04
source share