February 14th, 2008

MySQL suckage

mysql> select t1_id, value, length(value), substr(value, 1, 1), length(substr(value, 1, 1)) from t1;
+-------+--------+---------------+---------------------+-----------------------------+
| t1_id | value  | length(value) | substr(value, 1, 1) | length(substr(value, 1, 1)) |
+-------+--------+---------------+---------------------+-----------------------------+
|     1 | £200   |             5 | £                   |                           2 |
|     2 | test   |             4 | t                   |                           1 |
|     3 | €200   |             6 | €                   |                           3 |
+-------+--------+---------------+---------------------+-----------------------------+
3 rows in set (0.00 sec)

And in today's lesson, we learn that characters and bytes are not necessarily the same thing...

Edit: OK, so the MySQL reference docs do actually document that length() returns the length of the string in bytes (and char_length() returns the length in characters), but this is just putting a brave face on underlying retardedness.

  • Current Music
    Mesh - Crash
  • Tags
    ,