Trailing spaces in MySQL make me sad.

"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. This is true for all MySQL versions, and it makes no difference whether your version trims trailing spaces from VARCHAR values before storing them. Nor does the server SQL mode make any difference in this regard." – MySQL Documentation

Nice that they explain it in the documentation, but in my world 'abc ' (there is a space at the end of that) is not equal to 'abc' (no space at the end here).

mysql> select 'abc' = 'abc', 'abc ' = 'abc', ' abc' = 'abc', ' abc ' = 'abc';
+---------------+----------------+----------------+-----------------+
| 'abc' = 'abc' | 'abc ' = 'abc' | ' abc' = 'abc' | ' abc ' = 'abc' |
+---------------+----------------+----------------+-----------------+
|             1 |              1 |              0 |               0 |
+---------------+----------------+----------------+-----------------+
1 row in set (0.00 sec)

This week I learned that even people whose day job is MySQL can be unaware of or forget this.

 

Posted in Uncategorized | Tagged , | Leave a comment