Note because it was difficult
Something like this is stored in a jsonb column.
{
hoge: String,
items: String[]
}
So what I want to do is query ʻitemsthat contains one of the specific strings
[" a "," b "," c "]`.
In conclusion, I could use the following code.
items_to_query = ["a", "b", "c"]
Model.where("jsonbColumnName -> 'items' @> ?", items_to_query.to_json)
https://stackoverflow.com/questions/35737931/rails-postgres-query-with-jsonb-array https://www.postgresql.org/docs/9.4/functions-json.html
Recommended Posts