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

  • Reading Half-Marathon 2009

    Reading Half-Marathon 2009 Total 02:03:39 Position = 7626 out of ~17,000? The day didn't get off to too good a start: 6am on…

  • Getting back into training

    I guess it won't come as a surprise to those who know me that I've resolved to try and get fitter during the coming year. Which I've pretty much…

  • everyone's having a go...

    I see Mesh have a "God Rest Ye Merry Gentlemen" ditty on their Myspace page... Heading up to the parental home soon. Disorganised, as is…

  • 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