All threads / How to use LIKE to query a jsonb field

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to use LIKE to query a jsonb field

michel med asked in Rails

Hi guys, am really stuck with this, I have a jonb field called occurrences, and one of my records has this on it :

[{"occurs_on"=>"2019-02-04 23:00:00 UTC", "status"=>"none"}, 
{"occurs_on"=>"2019-02-05 23:00:00 UTC", "status"=>"none"}]

am trying do a query that check if there is any record with the date 2019-02-04

I tried this :

Event.where("events.occurrences ->> :key LIKE :value", 
:key => 'occurs_on', :value => '2019-02-04%')

But not working for me, any idea?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,344+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.