Antonio F.
Antonio F.

Reputation: 431

PostgreSQL LIKE operator doesn't match hyphen

I've a problem with LIKE operator in PostgreSQL. It does not match patterns that contain the - character. I've tried to escape these characters using the ESCAPE option, but it still does not work.

Query:

select * from footable where trascrizione like '% [---]is Abraam %';

Sample data (contents of column trascrizione):

[---]is Abraam [e]t Ise[---] / ((crux quadrata))

How can I solve this problem?

Upvotes: 0

Views: 3186

Answers (2)

user unknown
user unknown

Reputation: 36269

Please show the code. I have no problem:

SELECT * FROM a WHERE a LIKE '%-' AND b LIKE '%-%' AND c LIKE '-%';
  a   | b |  c   | d | e 
------+---+------+---+---
 foo- | - | -bar |   | 
(1 Zeile)

Upvotes: 0

cdhowie
cdhowie

Reputation: 169488

That pattern would not match because there is no space before [---]is Ambraam. There is a space in your pattern, between the % and [ characters, and it's requiring that space to be in your data. Try LIKE '%[---]is Abraam %'.

Upvotes: 1

Related Questions