CHARACTER is a standard SQL data type keyword that stores fixed-length character strings. When you declare a column or cast a value as CHARACTER(n) or CHAR(n), the database always reserves n bytes or characters, padding shorter strings with spaces on the right to reach the defined length. This predictable storage size can improve performance for small, uniformly sized codes such as country ISO codes or status flags. However, the padding means that trailing spaces are usually ignored in comparisons, and storing longer text wastes space. CHARACTER without a length defaults to 1 in most systems, but some dialects require the length explicitly. Because the value is padded on write, the stored size never shrinks until the column is updated.
n
(integer) - Required maximum length in characters or bytes, depending on the database encoding.CHAR, VARCHAR, CHARACTER VARYING, TEXT, NCHAR, CAST, COLLATION
SQL-86 standard
The database right-pads the value with spaces up to the defined length. When you retrieve the value the spaces are still stored, although many client tools trim them when displaying.
For small, uniform codes CHAR can improve indexing and storage predictability. For general text VARCHAR is usually better because it avoids wasting space.
Use TRIM or RTRIM functions: `SELECT TRIM(trailing FROM col) FROM table_name;` This strips the padding characters.
Yes. Use `ALTER TABLE table_name ALTER COLUMN col TYPE VARCHAR(n);` (syntax varies by dialect). The database rewrites the table to remove padding.