Steve Haslam (araqnid) wrote,
Steve Haslam
araqnid

  • Location:
  • Music:

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.

Tags: geek, sql
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments