Search Postgresql Archives

Re: LIKE with pattern containing backslash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	Jack Orenstein wrote:

In this code, The string passed to JDBC is %\% (percent, one
backslash, percent), and no rows are returned.
It appears as if the one backslash is being treated as an
escape for the %.

That's right. So \% as a pattern matches a percent, and \\ as a pattern matches a backslash. This has nothing to do with literals and all to do with the special role of backslash in LIKE.

From your program:

	   // Find rows with at least one backslash
String oneBackslash = new String(new char[]{'%', '\\',
'%'});

Actually, this will find rows ending with a percent.

	   // Find rows with at least two backslashes
String twoBackslashes = new String(new char[]{'%', '\\',
'\\', '%'});

Actually, this will find rows having at least one backslash.

The point is the lack of an ESCAPE clause to LIKE. Just add it to disable the special role of backslash and the patterns will match as you expect.

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux