Updated on 2023-07-20 GMT+08:00

ClickHouse Data Type

This section describes the data types of MRS ClickHouse.

For details about the ClickHouse data types, see ClickHouse Data Types.

Table 1 ClickHouse data types

Category

Keyword

Data Type

Description

Data type

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 type

Float32

Float

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

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 type

Decimal

Decimal

A signed fixed-point number that can ensure precision during addition, subtraction, and multiplication operations. The following formats are supported:

  • 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 type

String

String

A string can be of any length. It can contain any set of bytes, including empty bytes. The String type can replace the VARCHAR, BLOB, and CLOB types in other DBMSs.

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, this may reduce efficiency. The following values can be effectively stored in columns of the FixedString type:

  • IP address represented in binary (FixedString (16) for IPv6)
  • Language code (ru_RU, en_US...)
  • Currency code (USD, RUB...)
  • Hash value represented in binary mode (FixedString (16) for MD5 and FixedString (32) for SHA256)

Time and date type

Date

Date

The value is stored in two bytes, indicating the date value since 1970-01-01 (unsigned) to the current date. The time zone information is not stored.

DateTime

Timestamp

The value is a Unix timestamp stored in 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. The timestamp type value is accurate to second (no leap second). The system time zone will be used when the client or server is started.

DateTime64

DateTime64

This type allows you to store a time value in date plus time format.

Boolean type

Boolean

Boolean

ClickHouse does not have a type to store Boolean values. You can use the UInt8 and limit the value to be 0 or 1.

Array type

Array

Array

Array(T) is an array consisting of T elements. T can be of any type, including the array type. However, multi-dimensional arrays are not recommended. ClickHouse has limited support for multi-dimensional arrays. For example, you cannot store multidimensional arrays in a MergeTree table.

Tuple type

Tuple

Tuple

Each element of Tuple(T1, T2, ...) is of different type from other elements. Tuples cannot be stored in tables (except memory tables). Tuples can be used for grouping temporary columns. You can use IN expressions and lambda functions with specific parameters to group temporary columns.

Domains data type

Domains

Domains

Domains types are implementation-specific types.

IPv4 is a Domains type that is binary compatible with the UInt32 type and is used to store the value of an IPv4 address. It provides more compact binary storage while supporting recognition of more readable input and output formats.

IPv6 is a Domains type that is binary compatible with the FixedString (16) type and is used to store the value of an IPv6 address. It provides more compact binary storage while supporting recognition of more readable input and output formats.

Enumerated type

Enum8

Enum8

Value range: [–128, 127]

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

Enum16

Enum16

Value range: [–32768, 32767]

Nullable type

Nullable

Nullable

Unless otherwise specified in the ClickHouse server configuration, NULL is the default value for any Nullable type. Nullable fields cannot be contained in table indexes.

It 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 type

nested

nested

A nested data structure is like a table within a cell of another table. The parameters (column name and type) of the nested data structure are specified in the same way as in the CREATE TABLE query. Each table row can correspond to any number of rows in a nested data structure.

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