Updated on 2022-12-09 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 C, a single-precision floating point number occupies 4 bytes in storage of a computer and is described in 32-bit binary mode.

Float64

Double

Similar to the Double type in the C language, a double-precision floating point number occupies eight bytes in the machine and is described in 64-bit binary mode.

Decimal type

Decimal

Decimal

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

  • Decimal(P, S)
  • Decimal32(S)
  • Decimal64(S)
  • Decimal128(S)
NOTE:
  • P: precision. Valid range: [1:38]. It determines the number of decimal digits (including fractions) that can be contained.
  • S: scale. The value ranges from 0 to P, which determines the number of decimal places in the decimal part of a number.

String type

String

String

The character string can be of any length. It can contain any set of bytes, including empty bytes. Therefore, 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, the FixedString type is efficient. In other cases, this may reduce efficiency. Examples of values that can be effectively stored in columns of the FixedString type:

  • IP address represented in binary (IPv6 uses FixedString (16))
  • 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 from 1970-01-01 (unsigned) to the current time. The time zone information is not stored in the date.

DateTime

Timestamp

Stores Unix timestamps in four bytes (unsigned). Allows values within the same range as the date type to be stored. The minimum value is 1970-01-01 00:00:00. The timestamp type value is accurate to second (no leap second). The time zone uses the system time zone when the client or server is started.

DateTime64

DateTime64

This type allows you to store a time value in the form of date plus time.

Boolean type

Boolean

Boolean

ClickHouse does not have a separate type to store Boolean values. The UInt8 type can be used. The value can be 0 or 1.

Array type

Array

Array

Array(T): array consisting of T-type elements. T The value 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

Tuple(T1, T2, ...), tuple, in which each element has a separate type and tuples cannot be stored in tables (except memory tables). They can be used for temporary column grouping. In a query, IN expressions and lambda functions with specific parameters can be used 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 domain 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 value 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. 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, ...)