
Originally published on my blog: https://www.kevinpeters.net/how-to-query-with-postgre-sql-wildcards-like-a-pro/
How to filter with any...
For further actions, you may consider blocking this person and/or reporting abuse
Since you're running on Postgres, you can use
ILIKE
for a case-insensitiveLIKE
instead of multiple conditions! There are also a couple different flavors of regular expression which are even more flexible.The leading wildcard makes your "full-text search" non-sargable and therefore likely to perform poorly on larger tables or text fields. For actual full-text search you'll want to use tsvectors and to_tsquery().
Thanks, knew about
ILIKE
but this is just an extension for PostgreSQL. Regular expressions are of course more flexible. Also thanks for mentioning the full-text search. I will extend the article to include these points.Funny, I was just thinking about naming my next child Melloremipsum.
Great article! I always forget that you can use underscore in a LIKE.