I am currently trying to adjust the values stored in a table in MySQL. The values stored contain a series of Unicode characters. I need to truncate to 40 bytes worth of storage, but when I try:
UPDATE `MYTABLE` SET `MYCOLUMN` = LEFT(`MYCOLUMN`, 40);
MySQL is overly helpful and retains 40 characters, rather than 40 bytes. Is there a way to get around this?
Regards and with thanks,
gaioshin
I’m not quite sure if you really want to truncate to exactly 40 bytes.
Since you can get messed up unicode characters the condition should be
“MAX 40 bytes WITH the last character still being valid”.
I’d write a stored function for that. I’m not sure it works, but I guess, you catch my drift: