There is a table as below.
Books Table
-----------------------
COLUMN NAME | TYPE
id | integer
name | character varying
subjects | character varying []
subjects array types
when is stored as the {education, business, history} like this.I want to search for {history,business} in subjects.(For OR conditions, either history or business is fine.) How can I search for array type?
Book.where (subjects: ["hisotyr, business"]) didn't work.
postgresql ruby-on-rails querying
Book.where(Book.arel_table[:subjects].overlap(['hisotyr', 'business']))
or
Book.where.overlap(subjects: ['hisotyr', 'business'])
Book.where(Book.arel_table[:subjects].contains(['hisotyr', 'business']))
or
Book.where.contains(subjects: ['hisotyr', 'business'])
Please use the one that suits your needs. Above is &&& in sql, below is @>.
© 2024 OneMinuteCode. All rights reserved.