Skip to content

LowCardinality ​

LowCardinality(T) wraps a scalar type while preserving its comparison and function behavior. It can be useful for columns whose values come from a small repeated vocabulary, such as a status or category.

Syntax ​

text
LowCardinality(T)

Supported inner types ​

The inner type can be String, FixedString, an integer or floating-point number, a date, timestamp, clock, network address, UUID, Bool or Enum. These scalar domains may be nullable. Decimal and composite types are not accepted as the inner type.

The wrapper preserves the inner value's conversions, range checks and ordering. It is not a promise of column-wide on-disk compression or a guaranteed query speedup.

Examples ​

A status column ​

sql
CREATE TABLE orders(id UInt32, status LowCardinality(String));
INSERT INTO orders VALUES (1, 'new'), (2, 'new'), (3, 'paid');
sql
SELECT status, count(*) AS orders
FROM orders
GROUP BY status
ORDER BY status
FORMAT csv;
text
"new",2
"paid",1

Explicit conversion ​

to_low_cardinality constructs a wrapped scalar:

sql
SELECT to_type_name(to_low_cardinality('open')),
       lower(to_low_cardinality('OPEN'))
FORMAT csv;
text
"LowCardinality(String)","open"