Jean
Jean

Reputation: 621

PostgreSQL pattern LIKE not matching simple example

Hi I don't understand why my pattern does not work. It seems to be the same as in many examples I've seen on the Internet. Can you help?

select city from cities where city like 'ny';

56 rows

select city from cities where city like '[a-z][a-z]';

0 row

Upvotes: 0

Views: 928

Answers (1)

S-Man
S-Man

Reputation: 23666

LIKE is no comparator for Regular Expressions (Documentation)

You should take ~ comparator or SIMILAR TO:

demo:db<>fiddle

SELECT
    *
FROM cities
WHERE city ~ '[a-z][a-z]';

SELECT
    *
FROM cities
WHERE city SIMILAR TO '[a-z][a-z]';

Upvotes: 3

Related Questions