Bug #73095 | Select ... where unexpectedly returns a result when it shouldnt | ||
---|---|---|---|
Submitted: | 24 Jun 2014 15:00 | Modified: | 25 Jun 2014 10:05 |
Reporter: | Emmanuel Merliot | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 5.5.37 | OS: | Windows |
Assigned to: | CPU Architecture: | Any |
[24 Jun 2014 15:00]
Emmanuel Merliot
[24 Jun 2014 16:31]
Valeriy Kravchuk
Please, read the manual, http://dev.mysql.com/doc/refman/5.5/en/char.html: "All MySQL collations are of type PADSPACE. This means that all CHAR, VARCHAR, and TEXT values in MySQL are compared without regard to any trailing spaces. “Comparison” in this context does not include the LIKE pattern-matching operator, for which trailing spaces are significant."
[24 Jun 2014 20:07]
MySQL Verification Team
Please see Valery prior comment. Thanks.
[25 Jun 2014 10:05]
Emmanuel Merliot
Hello Valeriy, thank you for the quick answer. In the document you pointed me to: VARCHAR values are not padded when they are stored. Trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL. --> This is the behavior I expected actually. On the other hand, in the same doc: This means that all CHAR, VARCHAR, and TEXT values in MySQL are compared without regard to any trailing spaces One can be confused by the apparent contradiction between these two sentences. Trailing spaces can be understood as 'the characters the engine fill my string with, at the right'. These are not retrieved when you select the value. This is OK. These are not retrieved when you compare the value. This is OK. In the documentation, it seems trailing spaces are also 'the characters which are at the end of my string value when I inserted it, for example 'test space '. These are retrieved when you select the value. This is OK too. These are not retrieved when you compare the value. This is not OK in my case. Please could you consider explain more precisely the difference in the document? The final work around is actually not to use '=' operator but 'like' operator when one want to compare two strings binary-equality.