Skip to content

Instantly share code, notes, and snippets.

@ryantuck
Created January 10, 2017 20:01
Show Gist options
  • Save ryantuck/c1f779669425f667b1caa2acadfec838 to your computer and use it in GitHub Desktop.
Save ryantuck/c1f779669425f667b1caa2acadfec838 to your computer and use it in GitHub Desktop.
-- find rows where a certain key exists
select
*
from
my_table
where
json_field::jsonb ? 'key_i_want'
;
-- get certain key from json field
select
json_field::jsonb -> 'key_i_want'
from
my_table
;
-- the following syntax also works for referencing particular fields
select
json_field ->> 'key_i_want'
from
my_table
where
json_field::jsonb ? 'some_qualifier' and
json_field ->> 'other_key' = 'blah'
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment