Bug #48309 | Unexpected SELECT result looking for a space terminated string value | ||
---|---|---|---|
Submitted: | 26 Oct 2009 13:43 | Modified: | 29 Oct 2009 16:11 |
Reporter: | Alessio Cecchin | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Command-line Clients | Severity: | S2 (Serious) |
Version: | 5.0.51 | OS: | Linux (Debian 4.0 (Etch)) |
Assigned to: | CPU Architecture: | Any | |
Tags: | Debian, MYSQL SERVER, query, SELECT, ubuntu, where statement |
[26 Oct 2009 13:43]
Alessio Cecchin
[26 Oct 2009 13:58]
Valeriy Kravchuk
I think our manual, http://dev.mysql.com/doc/refman/5.0/en/char.html, explains this behaviour completely. "VARCHAR values are not padded when they are stored. Handling of trailing spaces is version-dependent. As of MySQL 5.0.3, trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL." etc So, you see space as it was stored. Also the following apply: "All MySQL collations are of type PADSPACE. This means that all CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces." Please, check.
[29 Oct 2009 16:11]
Alessio Cecchin
I see, yes. I add a (dirty) workaround into my PHP code (I'm writing an import class and I may not trim the string BEFORE adding it to DB w/o making a conflict!). BTW may be cool that DB admins will CHOICE what kind of character have to fill the varchar fields (I think to a directive into my.cnf file, for example). Using a \0 chr I may avoid the unexpected result. Don't you think?