views:

29

answers:

2

I am using mysql data base with rails. I have created a field of type of string. Are there any limits to its length? What about type text? Also as text is variable sized , I believe there would be extra costs associated with using text objects . How important can they get , if at all ?

+1  A: 

See the mySQL manual on String Types.

Varchar (String):

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

Text: See storage requirements

If you want a fixed size text field, use CHAR which can be 255 characters in length maximum. VARCHAR and TEXT both have variable length.

Pekka
This isn't relevant to migrations, which uses "string" and "text"
mathepic
@~mathepic there was no mention of Rails in the original question - only mySQL. Thanks for the heads up though.
Pekka
+3  A: 

String, in general, should be used for short text. For example, it is a VARCHAR(255) under MySQL.

Text uses the larger text from the database, like, in MySQL, the type TEXT.

For information on how this works and the internals in MySQL and limits and such, see the other answer by Pekka.

If you are requesting, say, a paragraph, I would use text. If you are requesting a username or email, use string.

mathepic