This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the databases category.
Last Updated: 2024-11-23
I ran a query in production to check if I had any products entities with name field containing the string "criminal" (e.g. "criminal law notes")
Product.where("name LIKE '%criminal%'").to_a
I got no results, so took thit to mean I had no such products in my database.
In reality I had many "criminal law" products - just with different capitalization - i.e. "Criminal law". My error was to forget that LIKE is case sensitive. I should have used ILIKE, which matches more flexibly:
Product.where("name ILIKE '%criminal%'").to_a