CHAR
This article covers the CHAR data type. See CHAR Function for the function.
Syntax
Description
A fixed-length string that is always right-padded with spaces to the specified
length when stored. M
represents the column length in characters. The range
of M
is 0
to 255
. If M
is omitted, the length is 1
.
CHAR(0) columns can contain 2 values: an empty string or NULL. Such columns cannot be part of an index. The CONNECT storage engine does not support CHAR(0).
Note: Trailing spaces are removed when CHAR
values are retrieved
unless the PAD_CHAR_TO_FULL_LENGTH
SQL mode is enabled.
If a unique index consists of a column where trailing pad characters are stripped or ignored, inserts into that column where values differ only by the number of trailing pad characters will result in a duplicate-key error.
Examples
Trailing spaces:
Example of CHAR:
Data Too Long
When SQL_MODE is strict (the default) a value is considered "too long" when its length exceeds the size of the data type, and an error is generated.
Example of data too long behavior for CHAR:
NO PAD Collations
NO PAD collations regard trailing spaces as normal characters. You can get a list of all NO PAD collations by querying the Information Schema Collations table, for example:
See Also
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?