Skip to content

Instantly share code, notes, and snippets.

View dwthien's full-sized avatar

Thien dwthien

View GitHub Profile
@dwthien
dwthien / rails-jsonb-queries
Created October 10, 2021 12:32 — forked from mankind/rails-jsonb-queries
Ruby on 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")
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 7114
Invalid Event Count: 0
=======================================================
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 8240
Invalid Event Count: 0
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 2219
Invalid Event Count: 0
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 2221
Invalid Event Count: 0
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 118
Invalid Event Count: 0
=======================================================
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 32063
Invalid Event Count: 0
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 1960
Invalid Event Count: 0
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 55866
Invalid Event Count: 0
This file has been truncated, but you can view the full file.
=======================================================
Begin Review
=======================================================
Count Summary
Valid Event Count: 55714
Invalid Event Count: 0