Text
Last updated on
11 February 2018
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Text data type is used to store quite large textual data, for example, the body field of a node. MySQL does not allow TEXT data types to have a default value other than NULL.
Sample Code:
$field['fieldname'] = array(
'type' => 'text',
'size' => 'small', // tiny | small | normal | medium | big
'not null' => FALSE,
'description' => t('stores fieldname for tablename table.'),
);
MySQL Field Mappings in schema.inc file :
'text:tiny' => 'TINYTEXT',
'text:small' => 'TINYTEXT',
'text:medium' => 'MEDIUMTEXT',
'text:big' => 'LONGTEXT',
'text:normal' => 'TEXT',
Maximum Length Allowed:
| Size | Maximum Length |
|---|---|
| tiny/small | 255 (2^8−1) bytes |
| normal | 65,535 (2^16−1) bytes |
| medium | 16,777,215 (2^24−1) bytes |
| big | 4,294,967,295 (2^32−1) bytes |
Words Estimate:
| Size | English Words (Estimate) | Multi-Byte Words (Estimate) |
|---|---|---|
| tiny/small | 44 (approx.) | 23 (approx.) |
| normal | 11,000 (approx.) | 5,900 (approx.) |
| medium | 2,800,000 (approx.) | 1,500,000 (approx.) |
| big | 740,000,000 (approx.) | 380,000,000 (approx.) |
Notes regarding words estimate:
- Words estimates are given here to help you select a text size for your field quickly.
- English words are calculated assuming an average of 4.8 bytes per word + 1 byte for interword spaces.
- Languages requiring multi-byte characters such as Greek, Arabic, Hebrew, Hindi, Thai, etc, etc typically require two bytes per character in UTF-8. We have assumed 11 bytes per word for these languages.
Storage Information :
Text is a variable-length data type. The required disk space depends only on the length of the stored string and not on the maximum length.
They take following storage space:
tiny /small : L + 1 bytes, where L < 2^8
normal : L + 2 bytes, where L < 2^16
medium : L + 3 bytes, where L < 2^24
long : L + 4 bytes, where L < 2^32Note: L represents the actual length in bytes of a given string stored.
Similarities with varchar :
- Both are variable-length data types, the required disk space depends only on the length of the stored string and not on the maximum length.
- The maximum length of both varchar and text is 65,535 bytes.
Comparison with varchar :
- We can limit the max size of varchar fields but not of text.
- We can index varchar but the text is available for an only full-text index.
- If you need to have a default value that is not null, you have to use varchar.
- If you need storage space more than 64kB, you have to use medium/long text.
- Because of storage implications, it is preferable to use varchar instead of text
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.