ClickHouse provides signed (Int) and unsigned (UInt) integers in various sizes. Choose the smallest type that fits your data range for optimal storage efficiency.
from typing import Annotated class Metrics(BaseModel): small_value: Annotated[int, "int8"] # Int8 medium_value: Annotated[int, "int16"] # Int16 user_id: Annotated[int, "int32"] # Int32 big_value: Annotated[int, "int64"] # Int64from typing import Annotated class Counters(BaseModel): flags: Annotated[int, "uint8"] # UInt8 port: Annotated[int, "uint16"] # UInt16 count: Annotated[int, "uint32"] # UInt32 total: Annotated[int, "uint64"] # UInt64| ClickHouse Type | TypeScript Helper | TypeScript Verbose | Python | Range |
|---|---|---|---|---|
Int8 |
Int8 |
number & ClickHouseInt<"int8"> |
Annotated[int, "int8"] |
| -128 to 127 |
Int16 | Int16 | number & ClickHouseInt<"int16"> | Annotated[int, "int16"] | -32,768 to 32,767 |
Int32 | Int32 | number & ClickHouseInt<"int32"> | Annotated[int, "int32"] | -2.1B to 2.1B |
Int64 | Int64 | number & ClickHouseInt<"int64"> | Annotated[int, "int64"] | ±9.2×10¹⁸ |
UInt8 | UInt8 | number & ClickHouseInt<"uint8"> | Annotated[int, "uint8"] | 0 to 255 |
UInt16 | UInt16 | number & ClickHouseInt<"uint16"> | Annotated[int, "uint16"] | 0 to 65,535 |
UInt32 | UInt32 | number & ClickHouseInt<"uint32"> | Annotated[int, "uint32"] | 0 to 4.2B |
UInt64 | UInt64 | number & ClickHouseInt<"uint64"> | Annotated[int, "uint64"] | 0 to 18.4×10¹⁸ |
Use the smallest integer type that fits your data. For example, use UInt8 for values 0-255 (like status codes), UInt16 for ports, and Int32 for most IDs. This reduces storage and improves cache efficiency.