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: