Text datatype

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Text datatype

Post by fractalvibes »

I had designed a MySQL table with one column defined as VarChar(250).

When I asked for some data to test with, I quickly realized that the column needed to be more like 3000 bytes. The Mascon client I often use would let me specify a text column, but not the max size.

Question is - if we add a row that simply has ABC - is this variable length, and am I just storing those three bytes plus whatever is needed to store the length of that field, or am I storing some huge - 2^16 or some such?

A little worried, as I could not specify a max size, but I gather that this is
calculated and taken care of by MySql...

thanks,

Phil J.
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

If you need to have bigger fields you have to use the blob fields. I think thers two diffrent kinds in mysql, binary and text. You probably want to use a text-blob if you just want to store a string. You do not need to specify the size of the blob, I think theres three diffrent type's of binary and text blob. The type determines the max-size.

Check the mysql manual pages for more info.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Thanks for the reply, Haagen and Mac. I am used to supplying a maxsize even with BLOB datatypes in DB2, so I was left with an uneasy feeling when MySQL would not allow this...

So I gather that a column defined as Text, in a particular instance I store the string 'ABC' - it actually is storing only 3 bytes plus however many bytes are needed to represent the actual size? i.e. variable length.

thanks,

Phil J.
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

I think it's 4 bytes + data size. It's all in the manual :)
Post Reply