Skip to content

Instantly share code, notes, and snippets.

@porjo
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save porjo/9886861 to your computer and use it in GitHub Desktop.
Save porjo/9886861 to your computer and use it in GitHub Desktop.
Postgresql: JSON operations cheatcheet
-- Select empty JSON field
select * from mytable where jsonfield::text = '{}'
-- Select 'title' within JSON field
select * from mytable where jsonfield->>'title' = 'Great Expectations'
select * from mytable where jsonfield->>'title' like 'Great Expectations%'
-- Update: Postgres 9.3 you must update whole field
update mytable set jsonfield = '{}' where id = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment