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?

Reply
Join the discussion
Create an account Log in

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

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

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