Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres - WHERE clause on whether values contain a certain string

If I want to retrieve all entries such that the column foo value contains a string 'bar', is there a simple way to do this in SQL, or Postgresql?

Something like ' WHERE foo = "bar"' but instead of = it would be something like ' WHERE foo CONTAINS "bar"'.

Postgres Version 9.3

like image 254
tscizzle Avatar asked May 21 '15 15:05

tscizzle


1 Answers

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%'
like image 67
John Hodge Avatar answered Sep 29 '22 01:09

John Hodge