Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: ILIKE in all text columns

Is there a simple ad-hoc way to execute a ILIKE query on all text columns of a table?

I know that there is a cell which contains "foobar". But the table has a lot of columns and only 50k rows, so searching all columns and rows should be fast.

like image 593
guettli Avatar asked May 18 '21 15:05

guettli


1 Answers

I'm giving you this query with the understanding that this is NOT something you'd use for performance, just backfill and cleanup (which seems to be the case here):

SELECT * 
FROM tablename foo 
WHERE LOWER(foo::text) LIKE '%foobar%'

If you want to implement some moderately performant free text searching, you'd want to go through the effort of creating an indexed tsvector/weighted tsvector column.

like image 179
John Morton Avatar answered Nov 14 '22 23:11

John Morton