Postgres - WHERE clause on whether values contain a certain string
One of:
WHERE foo LIKE '%bar%'
WHERE foo ILIKE '%bar%' --case insensitive
WHERE foo ~* 'bar' --regex
WHERE foo ~* '\ybar\y' --matches bar but not foobar (\y is word boundary)
WHERE foo::tsvector @@ 'bar'::tsquery --matches bar but not foobar
You can index foo
to make LIKE
, ILIKE
, and regexp
searches faster: http://www.postgresql.org/docs/9.3/static/pgtrgm.html#AEN154464
Or use a GIN or GIST index on a full-text column
Use the SQL LIKE
statement. With that, you use a %
as a wildcard. So, your WHERE
statement could be something like:
WHERE foo LIKE '%bar%'