Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL LIKE operator with wildcard and backslash
    primarykey
    data
    text
    <p>It's frustrated with MySQL's pattern escaping used in LIKE operator.</p> <pre><code>root@dev&gt; create table foo(name varchar(255)); Query OK, 0 rows affected (0.02 sec) root@dev&gt; insert into foo values('with\\slash'); Query OK, 1 row affected (0.00 sec) root@dev&gt; insert into foo values('\\slash'); Query OK, 1 row affected (0.00 sec) root@dev&gt; select * from foo where name like '%\\\\%'; Empty set (0.01 sec) root@dev&gt; select * from foo; +------------+ | name | +------------+ | with\slash | | \slash | +------------+ 2 rows in set (0.00 sec) root@dev&gt; select * from foo where name like '%\\\\%'; Empty set (0.00 sec) root@dev&gt; select * from foo where name like binary '%\\\\%'; +------------+ | name | +------------+ | with\slash | | \slash | +------------+ 2 rows in set (0.00 sec) </code></pre> <p>According to MySQL docs: <a href="http://dev.mysql.com/doc/refman/5.5/en/string-comparison-functions.html#operator_like" rel="nofollow">http://dev.mysql.com/doc/refman/5.5/en/string-comparison-functions.html#operator_like</a> <code>%\\\\%</code> is the right operand, but why it yields no result?</p> <p>EDIT: The database I'm testing that in has character_set_database set to utf8. To further my investigation, I created the same setup in a database that has character_set_database set to latin1, and guess what, <code>'%\\\\%'</code> works!</p> <p>EDIT: The problem can be reproduced and it's the field collation problem. Details: <a href="http://bugs.mysql.com/bug.php?id=63829" rel="nofollow">http://bugs.mysql.com/bug.php?id=63829</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload