tags:

views:

35

answers:

2

Given a table like so:

id      |    value
-------------------
1       |     food
2       |     foot
3       |     barfoo
4       |     bar
5       |     baz

Using postgres I want to find all of the rows where the value field matches from the start of the search field. Sort of like SELECT * FROM table where 'foo' ilike value%

Searching for 'foo' would return food and foot but not barfoo.

I think this should be easy but I'm missing something obvious.

A: 

You have the arguments to ILIKE the wrong way round:

SELECT * FROM table where value ilike 'foo%'
Mark Byers
+2  A: 

shouldn't the comparison be switched

where value ilike 'foo%'

Edit

  • Changed to Case Insensitive "ilike", per original example.

So many SQL dialects, so little greymatter storage space.

Rawheiser
+1: This was the first correct answer.
Mark Byers
You might want to change "like" to "ilike" though, to match the question.
Mark Byers
thanks, you've answered the question correctly, I've just noticed that I asked the wrong question though. Never mind.
dsas