Rails Postgres Order Case When
def self.order_by_ids(ids)
  order_by = ["CASE"]
  ids.each.with_index do |id, index|
    order_by << "WHEN id=#{id} THEN #{index}"
  order_by << ["END"]
  order_by.join(" ")
SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[]
SELECT value_variable = ANY ('{1,2,3}'::int[])

Rails Sorting the record based on the array passed in where condition https://stackoverflow.com/questions/16606357/how-to-make-a-select-with-array-contains-value-clause-in-psql Check if value exists in Postgres array Ordering a query result set by an arbitrary list in PostgreSQL