0

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?

5
  • Show us your query and some data you expect to match. Commented Aug 20, 2011 at 18:44
  • this is a semplified example of my query: select * from footable where trascrizione like '% [---]is Abraam %'; it returns a void result set (but I know that there's one record that matchs). Commented Aug 20, 2011 at 18:48
  • And what is the row you expected to match? Commented Aug 20, 2011 at 18:51
  • The row that has this value for the field trascrizione: "[---]is Abraam [e]t Ise[---] / ((crux quadrata))" Commented Aug 20, 2011 at 18:53
  • 1
    @Antonio F.: Your duty is to clarify your question by editing it, not by making it clear in the comments. The question should be answerable by just reading the question. Commented Aug 20, 2011 at 19:04

2 Answers 2

1

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 %'.

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

1 Comment

Thank you. The problem was not the abscence of whitespace between '[' and '-', but a whitespace before the '%' and '['. I have to trim the string.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.