I was doing some query debugging and have found that I was getting unexpected (though apparently correct) TRUEs for when comparing a varchar field to a literal. Specifically the following:
- the row in question is just an auto-increment int primary key, and a varchar(255)
- to set up add a single row:
insert into comp_test(test_string) values('TestString');
where test_string='tESTsTRING'
clause is truewhere test_string='TestString '
clause is true (it's padded with blank space at the end)
So while constructing my questions I can across a similar post post describing the cause and how to force case sensitivity (with BINARY and COLLATE among others). Will the BINARY and COLLATE solutions also cause blank padding to make the clause false?
I now have part of the solution, but can anyone explain why equivalance comparison is so sloppy? In the case above if the value in test_string is an 8 character string, there are ~64,000 literals that will cause the comparison to evaluate to true. What kind of equivalance is that? It seems wrong and nearly all other languages would never permit anything but 1 to 1 equivalance.
Thanks in advance.