Reputation: 1082
I have a jsonb column named 'available_quantity'. which will have sample values
{ "100": 50, "1000":10 }
Now, I want to query all keys with values less than 50.
I tried this query,
Bundle.where('available_quantity @> ?', {'100': 5}.to_json)
But this one gives me all the Bundle with available_quantity containing {100: 5}.
How can I do that? Is that even possible?
Upvotes: 1
Views: 248
Reputation: 33420
You can use the ->>
operator:
Bundle.where("(available_quantity->>'100')::int < 50")
Upvotes: 1