Skip to content

Instantly share code, notes, and snippets.

View mahesh-krishnakumar's full-sized avatar

Mahesh Krishna Kumar mahesh-krishnakumar

  • Ultrahuman
  • Bangalore
  • 19:56 (UTC +05:30)
  • X @maheshk_87
View GitHub Profile
@mahesh-krishnakumar
mahesh-krishnakumar / rails-jsonb-queries
Created June 28, 2020 05:22 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
/* *******************************************************************************************
* THE UPDATED VERSION IS AVAILABLE AT
* https://github.com/LeCoupa/awesome-cheatsheets
* ******************************************************************************************* */
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html