Char
Last updated on
18 April 2018
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Char fields are fixed-length character fields. The length of the field, in characters, is defined by the length key. MySQL char field lengths are 0–255 characters.
Sample Code:
$field['fieldname'] = array(
'type' => 'char',
'length' => 50,
'not null' => FALSE,
'default' => 'Some Default',
'description' => t('field fieldname of tablename.'),
);MySQL Mapping in the schema.ini file:
'char:normal' => 'CHAR',The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. For example, you store the word "test" in a char(10) column, "test " actually gets stored in the table.
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.