MySQL making whitespace matter -


apparently rare issue, imo extremely annoying , wrong: trailing whitespace in mysql aren't used in comparison:

mysql> select "a" = "a "; +------------+ | "a" = "a " | +------------+ |          1 | +------------+ 1 row in set (0.00 sec) 

this problematic in following scenario:

mysql> select count(*) eq name != trim(name); +------------+ | count(*)   | +------------+ |          0 | +------------+ 1 row in set (0.00 sec)  mysql> update eq set name=trim(name); query ok, 866 row affected (0.01 sec) rows matched: 650907  changed: 866  warnings: 0 

is there way configure mysql treat whitespace properly?

according the manual, 1 quick fix use like:

per sql standard, performs matching on per-character basis, can produce results different = comparison operator:

...

in particular, trailing spaces significant, not true char or varchar comparisons performed = operator ...

as long don't use wildcards, should identical =. stack overflow question seems support assumption: equals(=) vs. like

the manual doesn't state whether strcmp() stricter = in terms of whitespace, , can't try out right - might worth taking at, too, makes clearer why = not used.

binary comparison suggested tombom option, have other side-effects (like stricter comparison of umlauts, eg. a , Ä different) may or may not want. more info on effects of using binary comparison in this question.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -