CHAR
The CHAR
data type is conceptually a fixed-length character string that is padded with trailing blanks.
Trailing blanks are removed from strings in CHAR
columns when the data is stored. Blanks are restored on output to the client. A CHAR(5)
column, for example, returns 5 bytes to the client but may store fewer than 5 bytes in the database.
All CHAR
-related functions and operators work on a compact (trimmed) representation of the input data. A CHAR
string behaves exactly like a VARCHAR
string without the trailing spaces. For example, 'abc '::char(10)
is exactly equivalent to 'abc'::varchar(10)
.
For more details and examples, see Trailing Blanks in Character Data.
An attempt to load a string that is longer than the specified length of a CHAR
column results in a value too long
error.
In terms of the data type hierarchy for character strings, VARCHAR
has precedence over CHAR
, and CHAR
has precedence over UNKNOWN
.
A CHAR
column without a length specification defaults to a 1-byte column.
The maximum length of a CHAR
column is 64000 bytes. The maximum length of a row in a table is 64231 bytes. See Maximum Row Size.
Parent topic:SQL Data Types