Data types decide how ClickHouse stores, compresses, and computes column values, directly impacting speed and accuracy.
ClickHouse supplies Numeric, String, FixedString(N), Date/Time, UUID, Array, Tuple, Map, Enum, and Nullable(T)
wrappers. Choosing the smallest adequate type cuts disk usage, RAM, and CPU.
Store surrogate keys such as Customers.id
in UInt64
.Hold currency in Decimal(12,2)
to keep cents exact and avoid floating-point rounding.
CREATE TABLE Orders (
id UInt64,
customer_id UInt64,
order_date DateTime,
total_amount Decimal(12,2)
) ENGINE = MergeTree
ORDER BY id;
Use Date
for whole days, DateTime
for second resolution, or DateTime64(3)
for millisecond events like payment callbacks.
Wrap String
or Enum
columns with few distinct values—e.g., Customers.country
—in LowCardinality
to get dictionary compression and faster group-bys.
UInt64
.Decimal
for monetary fields.Nullable
only when missing values are expected.Enum8
/Enum16
for small, fixed value sets like order status.LowCardinality
on high-selectivity columns before production use.Avoid Float64
for totals; rounding errors accumulate.Define Decimal
scale and precision correctly or ClickHouse silently truncates values.
.
Yes. Boolean
is an alias for UInt8
; values are stored as 0 or 1.
Use ALTER TABLE ... MODIFY COLUMN
, but only to types ClickHouse can convert in place (e.g., UInt32 → UInt64). Otherwise create a new table and migrate.
Decimal128 offers up to 38 digits. Use it when your amounts exceed ~1026 or you require nano-currency precision.