Skip to content

FixedString ​

FixedString(n) stores exactly n bytes. Short input is padded with zero bytes; input longer than n bytes raises STRING_TOO_LONG.

Use this type when an external value has a fixed byte width. Use String or VARCHAR(n) when the requirement is about text characters.

Syntax ​

text
FixedString(n)
  • n — A positive byte length.

The size counts bytes, so a multibyte UTF-8 character can consume several positions. Padding is part of the value. Use hex to inspect it without embedding zero bytes in terminal output.

The length contract applies to casts, writes, defaults and generated values. A top-level column can contain SQL NULL unless declared NOT NULL.

Examples ​

Inspecting padding ​

sql
SELECT hex(CAST('a' AS FixedString(3))) AS bytes,
       length(CAST('a' AS FixedString(3))) AS byte_count
FORMAT csv;
text
"610000",3

An input at the exact byte length ​

sql
SELECT hex(CAST('abc' AS FixedString(3)))
FORMAT csv;
text
"616263"

Casting 'abcd' to FixedString(3) raises STRING_TOO_LONG.