Answer the question
In order to leave comments, you need to log in
Shielded backslash and ILIKE
Good afternoon!
select '%123\\456%'
expectedly returns the string %123\456% select '123456' ilike '%123\\456%'
unexpectedly gives true. Answer the question
In order to leave comments, you need to log in
The problem is that '%123\\456%' doesn't actually have a backslash ;)
A backslash is already an escape character in strings, and to cram one into a string, you have to write it twice. But in 'like' it is also an escape character, so to match one backslash with a like, it must also be escaped. In total, to match one backslash, you need to write it four times. Those. something like this:
plesk=> select E'\\' like E'%\\%';
?column?
- f
(1 row)
plesk=> select E'\\' like E'%\\\\%';
?column?
- t
(1 row)
Well, or specify another escape character:
plesk=> select E'\\' like E'%\\%' escape '#';
?column?
- t
(1 row)
So if the document is not found with four slashes, then everything is in order :)
Here it is written about it, 9.7.1: www.postgresql.org/docs/8.0/static/functions-matching.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question