Created
November 4, 2016 18:48
-
-
Save andrewscaya/df007aa07958ab4618f0e69225e520cd to your computer and use it in GitHub Desktop.
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 example ( | |
id INTEGER PRIMARY KEY NOT NULL, | |
data jsonb | |
); | |
INSERT INTO example (id, data) VALUES | |
(1, '{"name": "Paint house", "tags": ["Improvements", "Office"], "finished": true}'), | |
(2, '{"name": "Wash dishes", "tags": ["Clean", "Kitchen"], "finished": false}'), | |
(3, '{"name": "Cook lunch", "tags": ["Cook", "Kitchen", "Tacos"], "ingredients": ["Tortillas", "Guacamole"], "finished": false}'), | |
(4, '{"name": "Vacuum", "tags": ["Clean", "Bedroom", "Office"], "finished": false}'), | |
(5, '{"name": "Hang paintings", "tags": ["Improvements", "Office"], "finished": false}'); |
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
SELECT data->>'name' AS name FROM example; | |
SELECT * FROM example WHERE data->>'finished' = 'true'; | |
SELECT count(*) FROM example WHERE data ? 'ingredients'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment