1

I'm trying to select with the IN operator in postgreSQL.

When I write:

select name from table where name = 'Eastway'

or

select name from table where name like '%Oxford%'

then I have multiple results but

select name from table where name in ('Eastway', '%Oxford%')

does not return any value.

What am I doing wrong? And apologies for newbie question.

1
  • I noticed the issue was at upper and lower case strings :) Commented Nov 27, 2015 at 0:05

2 Answers 2

2

LIKE is a regular expresion comparasion

= is exact match

Your IN is equivalent to name ='Eastway' OR name = '%Oxford%'

But if you say on your first query you get multiple result. On your IN version should also have some result as well. The rows where name ='Eastway'

Sign up to request clarification or add additional context in comments.

1 Comment

I would say LIKE is a pattern matching comparison operator, since it does not support regular expressions. For regexes there is another SIMILAR or ~ operators. postgresql.org/docs/9.3/static/functions-matching.html
0

You can use or for this. Or a regular expression:

select name
from table
where name ~ '(^Eastway$)|Oxford';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.