0

I essentially want to perform a LIKE query on a PostgreSQL primary id column for a query generated using Squeel and I don't think Squeel is understanding the syntax I'm giving it. Any ideas?

Active Record

Task.where("(id::text LIKE ?)", "%1%").to_sql
=> "SELECT \"tasks\".* FROM \"tasks\"  WHERE ((id::text LIKE '%1%'))"

Squeel

Task.where{(id::text =~ "%#{criteria}%")}.to_sql
=> "SELECT \"tasks\".* FROM \"tasks\"  WHERE \"id\".\"text\" ILIKE '%criteria%'"
Thomas
  • 2,622
  • 1
  • 9
  • 16
  • Wow, it has been a while since I heard about that gem. AFAIR, that works on top of ActiveRecord, so why don't you just use the same `Task.where("(id::text LIKE ?)", "%1%")` you're giving as an example? squeel has been archived, and the last useful commit was done 8 years ago, so the chances that don't support PostgreSQL casting are high. – Alter Lagos Nov 04 '22 at 03:16
  • @AlterLagos The reason for not using ActiveRecord is because I was wanting to use other things in the squeel library and wasn't sure how to merge them either. For example I was wanting to use the `|` operator to concatenate queries with an "or". Though I can do this with Active Record as well. – Thomas Nov 04 '22 at 17:42

0 Answers0