Last active
April 20, 2017 09:43
-
-
Save FrontierPsychiatrist/ce72fcb35196b8edb6b5d807a1080b8f to your computer and use it in GitHub Desktop.
Postgres JSON for API responses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE api_responses ( | |
name VARCHAR, | |
body JSONB | |
); | |
INSERT INTO api_responses (name, body) | |
VALUES ('request-x', '{ "id": 1234, "data": { "people": [ { "name": "Moritz", "github": "FrontierPsychiatrist" }, { "name": "Alexander", "github": "alexhanschke" } ] } }'); | |
SELECT people->'name', people->'github' | |
FROM api_responses, jsonb_array_elements(body->'data'->'people') people WHERE name = 'request-x'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment