# db/migrate/20140207133952_create_books.rbcreate_table:booksdo|t|t.string'title't.string'tags',array: truet.integer'ratings',array: trueendadd_index:books,:tags,using: 'gin'add_index:books,:ratings,using: 'gin'# app/models/book.rbclassBook<ApplicationRecordend# UsageBook.createtitle: "Brave New World",tags: ["fantasy","fiction"],ratings: [4,5]## Books for a single tagBook.where("'fantasy' = ANY (tags)")## Books for multiple tagsBook.where("tags @> ARRAY[?]::varchar[]",["fantasy","fiction"])## Books with 3 or more ratingsBook.where("array_length(ratings, 1) >= 3")