Updated on 2024-04-29 GMT+08:00

Data Types

This section describes the data types that are supported by ClickHouse.

Supported Data Types

Table 1 Supported data types

Type

Keyword

Data Type

Description

Integer

Int8

Int8

Value range: [–128, 127]

Int16

Int16

Value range: [–32768, 32767]

Int32

Int32

Value range: [–2147483648, 2147483647]

Int64

Int64

Value range: [–9223372036854775808, 9223372036854775807]

Floating point

Float32

Single-precision floating point

Similar to the Float type in the C programming language. A single-precision floating point number occupies four bytes in storage of a computer and is represented in 32-bit binary.

Float64

Double-precision floating point

Similar to the Double type in the C programming language. A double-precision floating point number occupies eight bytes in storage of a computer and is represented in 64-bit binary.

Decimal

Decimal

Decimal

A signed fixed-point number that can ensure precision during addition, subtraction, and multiplication operations. Decimal values can be in the following formats:

  • Decimal(P, S)
  • Decimal32(S)
  • Decimal64(S)
  • Decimal128(S)
    NOTE:

    P stands for precision. The valid range is [1:38]. It determines the number of decimal digits (including fractions) that can be contained.

    S stands for scale. The valid range is [0:P]. It determines the number of decimal places of a number.

String

String

String

A string can be of a random length. It can contain any set of bytes, including null bytes. Therefore, the String type can replace the VARCHAR, BLOB, and CLOB types in other database management systems.

FixedString

Fixed-length string

When the length of the data happens to be N bytes, using the FixedString type is more efficient than other types. In other cases, efficiency may be impaired. The following values can be effectively stored in columns of the FixedString type:

  • IP addresses represented in binary (FixedString (16) for IPv6)
  • Language codes (ru_RU, en_US...)
  • Currency codes (USD, RUB...)
  • Binary representation of hash values (FixedString (16) for MD5 and FixedString (32) for SHA256)

Date and time

Date

Date

A Date value takes up two bytes, indicating the date value from 1970-01-01 (unsigned) to the current time. Date values are stored without the time zone.

DateTime

Timestamp

A Unix timestamp value takes up four bytes (unsigned). Value range of this type is the same as the Date type. The minimum value is 1970-01-01 00:00:00. Timestamp values are accurate to seconds. Leap seconds are not supported. The system time zone will be used when the client or server is started.

DateTime64

DateTime64

This type allows you to store both the date and time of a specific point in time.

Boolean

Boolean

Boolean

ClickHouse does not support the Boolean type. You can use the UInt8 type for Boolean values. Valid values are 0 and 1.

Array

Array

Array

An Array value is a collection of elements of the same data type. The elements can be of a random data type, even the Array type itself. However, multi-dimensional arrays are not recommended, because ClickHouse supports multi-dimensional arrays only to a limited extent. For example, you cannot store multi-dimensional arrays in MergeTree tables.

Tuple

Tuple

Tuple

A Tuple value is a collection of elements of different data types. Tuple values cannot be stored in tables, except for memory tables. You can use Tuple values to group temporary columns. In queries, you can use IN expressions and lambda functions with specific parameters to group temporary columns.

Domains

Domains

Domains

The implementation of the Domains type varies based on different values:

  • If the values are IPv4 addresses, the Domains type is binary compatible with the UInt32 type. Compared with the UInt32 type, the Domains type saves the binary storage space and supports more readable input and output formats.
  • If the values are IPv6 addresses, the Domains type is binary compatible with the FixedString (16) type. Compared with the FixedString (16) type, the Domains type saves the binary storage space and supports more readable input and output formats.

Enumeration

Enum8

Enum8

Value range: [–128, 127]

An Enum value stores the mapping of 'string'= integer, for example, Enum8('hello' = 1, 'world' = 2).

Enum16

Enum16

Value range: [–32768, 32767]

Nullable

Nullable

Nullable

Unless otherwise stated in ClickHouse server configurations, the default value of the NULLABLE type is NULL. Nullable values cannot be included in table indexes.

Nullable values can be stored together with the normal values of TypeName. For example, columns of the Nullable(Int8) type can store values of the Int8 type, while rows without values store NULL.

Nested

nested

nested

A nested data structure is similar to a table inside a cell. You can specify the parameters of a nested data structure, such as field name and data type, the same way that you specify parameters in a CREATE TABLE statement. Each row in a CREATE TABLE statement can correspond to a random number of rows in a nested data structure.

Example: Nested (Name1 Type1,Name2 Type2, ...)