The fixed-length character string type of SQL is character
, the shorter char
is a synonym.
CREATE TABLE … (
currency CHAR(3)
)
The character
type can be parameterized to set its length—like 3 in the example. Note that the unit are characters, not bytes.✓✗ In absence of the length, the length defaults to 1 character.
Values shorter than the length are space-padded at the end to reach the required length. Note that pad space
collations cause fixed-length string comparisons to behave similar to variable-length string comparisons.
As the type character
stores characters, rather than bytes, the character set
and collate
clauses may be specified.
bpchar
(without length) is a variable-length stringThe SQL types character
and char
are defined in ISO/IEC 9075-2:2023 as mandatory feature E021-01, “CHARACTER data type (including all its spellings)”. They were already available in SQL-92 (entry level).
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-sql.com on your radar.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »