Skip to content

Instantly share code, notes, and snippets.

@zachjamesgreen
Last active March 31, 2016 16:02
Show Gist options
  • Save zachjamesgreen/73599779083c0c39c70f7e9430706e30 to your computer and use it in GitHub Desktop.
Save zachjamesgreen/73599779083c0c39c70f7e9430706e30 to your computer and use it in GitHub Desktop.
Snippets of ruby code for psql and also psql snippets ive found

#STUFF

Query array of hstore

select * from TABLE where TERM = ALL (SELECT unnest(COLUMN)->HSTORE_KEY);

Add scope using array of hstore

scope :where_any, ->(key, value) { where("? = ANY (SELECT unnest(\"items\") -> ?)", value, key) }
scope :where_all, ->(key, value) { where("? = ALL (SELECT unnest(\"items\") -> ?)", value, key) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment