Fixedstring
To declare a column of FixedString
type, use the following syntax:
Where N
is a natural number.
The FixedString
type is efficient when data has the length of precisely N
bytes. In all other cases, it is likely to reduce efficiency.
- The binary representation of IP addresses (
FixedString(16)
for IPv6). - Currency codes (USD, RUB … ).
To store UUID values, use the UUID data type.
When inserting the data, ClickHouse:
- Complements a string with null bytes if the string contains fewer than
N
bytes.
When selecting the data, ClickHouse does not remove the null bytes at the end of the string. If you use the WHERE
clause, you should add null bytes manually to match the FixedString
value. The following example illustrates how to use the clause with FixedString
.
The query SELECT * FROM FixedStringTable WHERE a = 'b'
does not return any data as a result. We should complement the filter pattern with null bytes.
This behaviour differs from MySQL for the CHAR
type (where strings are padded with spaces, and the spaces are removed for output).
Note that the length of the FixedString(N)
value is constant. The function returns N
even if the value is filled only with null bytes, but the empty function returns 1
in this case.