?

Log in

No account? Create an account

Previous Entry | Next Entry

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:

Comments

( 2 comments — Leave a comment )
dmh
Feb. 14th, 2008 07:21 pm (UTC)
Ah, the joys of UTF-8! :o)
araqnid
Feb. 14th, 2008 10:05 pm (UTC)
I don't have a problem with UTF-8, in general... but things like this mess suggest that others do :|
( 2 comments — Leave a comment )

Profile

araqnid
Steve Haslam

Latest Month

March 2009
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Page Summary

Powered by LiveJournal.com
Designed by Tiffany Chow