I havejsonb columnfeeds with data in the form of this:
[{ "id": 99999999, "lang": "pt", "entities": { "urls": [], "media": [{ "id": 123456456, "type": "photo", "id_str": "123456456", "indices": [37, 59], }] }, "favorited": false, "retweeted": false, "truncated": false}]How do I query thefirstmedia ->> id since it's in an json array? So that the result is like this:
id media_id---------------------------99999999 123456456I triedjsonb_array_elements but can't seem to get the output I want, especially the part where themedia is nested within another array.
2 Answers2
Figured it out
SELECT jsonb_array_elements(feeds)->>'id', (((jsonb_array_elements(feeds)->'entities')->'media')->0)->>'id' as mediaFROM mytable Sign up to request clarification or add additional context in comments.
Comments
select feeds::jsonb->0->>'entities'->>'media'->0->>'id' from table;Comments
Explore related questions
See similar questions with these tags.
