Search Postgresql Archives

Re: LIKE with pattern containing backslash

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

 



	Jack Orenstein wrote:

Can someone help in my understanding of what is correct
behavior (in the literal and bound variable cases)?
Is there a bug in the driver? in postgres? in the docs? Or in my understanding?

LIKE E'%\\%' will match a string that ends with a percent sign, not a string that contains a backslash. That's because the backslash acts additionally as the default escape character for LIKE patterns.
You can add ESCAPE '' after the LIKE statement to avoid that.
Otherwise you get really two levels of different backslash interpretation here, one for the string parser and one for the LIKE operator, and that doesn't take into account any additional level needed if you embed the query into a source code string. Embedding "like backslash" in a C string is a kind of worst case, you really need to write: "LIKE E'\\\\\\\\'" (8 backslashes) which looks ridiculous but is the correct form. The C compiler will reduce 8 to 4. The SQL parser will reduce 4 to 2. The LIKE operator will reduce 2 to 1.

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