views:

73

answers:

4

I am saving a raw email in a TEXT column in MySQL with Ruby on Rails. It keeps getting truncated to 65535 characters, does anyone know what causes this?

MySQL is running with max_allowed_packet=64M

A: 

65535 is one of those "magic numbers" - it's 2^16 - 1. That's just what the maximum limit is for a TEXT column in MySQL.

Matt Ball
+3  A: 

It gets truncated to that length because... well, that's what will fit in a TEXT column.

You need MEDIUMTEXT or LONGTEXT if you want to store more than that.

Michael Madsen
Can you quote what you read on that page? I cant see where it gives this as the limit...
Greg
Under "Storage Requirements for String Types in MyISAM", there's a table stating that BLOB and TEXT require L + 2 bytes of storage space, where L "represents the actual length in bytes of a given string value", and, according to the table, is less than 2^16 (65,536). Consequently, you can't store more than that. MEDIUMTEXT will give you 16,777,215 bytes of storage, while LONGTEXT gives you just short of 4.3 billion bytes.
Michael Madsen
Note that even though it says MyISAM, the same applies to InnoDB, as the two storage engines don't have any difference as far as BLOB/TEXT storage limits are concerned.
Michael Madsen
A: 

Ruby on Rails didn't truncate, MySQL did.

The TEXT type is limited to 2^16 - 1 = 65535 characters, see the documentation.

streetpc
A: 

I'm not a Ruby expert, but the number 65535 caught my attention -- that's 16 bits (minus 1, which typically is special). You're probably running up against a wall of the size limit of the type you're using.

statichippo