Skip to content
ClickHouse Docs

Int | UInt Types

Autogenerated from ClickHouse system tables

Int128

A 128-bit signed integer. See the Int32 entry for the full documentation of the integer types.

Syntax

Int128

Related

  • Int32

Int16

A 16-bit signed integer. See the Int32 entry for the full documentation of the integer types.

Syntax

Int16

Related

  • Int32

Int256

A 256-bit signed integer. See the Int32 entry for the full documentation of the integer types.

Syntax

Int256

Related

  • Int32

Int32

ClickHouse offers a number of fixed-length integers, with a sign (Int) or without a sign (unsigned UInt) ranging from one byte to 32 bytes.

When creating tables, numeric parameters for integer numbers can be set (e.g. TINYINT(8), SMALLINT(16), INT(32), BIGINT(64)), but ClickHouse ignores them.

Integer Ranges

Integer types have the following ranges:

Type Range
Int8 [-128 : 127]
Int16 [-32768 : 32767]
Int32 [-2147483648 : 2147483647]
Int64 [-9223372036854775808 : 9223372036854775807]
Int128 [-170141183460469231731687303715884105728 : 170141183460469231731687303715884105727]
Int256 [-57896044618658097711785492504343953926634992332820282019728792003956564819968 : 57896044618658097711785492504343953926634992332820282019728792003956564819967]

Unsigned integer types have the following ranges:

Type Range
UInt8 [0 : 255]
UInt16 [0 : 65535]
UInt32 [0 : 4294967295]
UInt64 [0 : 18446744073709551615]
UInt128 [0 : 340282366920938463463374607431768211455]
UInt256 [0 : 115792089237316195423570985008687907853269984665640564039457584007913129639935]

Integer Aliases

Integer types have the following aliases:

Type Alias
Int8 TINYINT, INT1, BYTE, TINYINT SIGNED, INT1 SIGNED
Int16 SMALLINT, SMALLINT SIGNED
Int32 INT, INTEGER, MEDIUMINT, MEDIUMINT SIGNED, INT SIGNED, INTEGER SIGNED
Int64 BIGINT, SIGNED, BIGINT SIGNED

Unsigned integer types have the following aliases:

Type Alias
UInt8 TINYINT UNSIGNED, INT1 UNSIGNED
UInt16 SMALLINT UNSIGNED, YEAR
UInt32 MEDIUMINT UNSIGNED, INT UNSIGNED, INTEGER UNSIGNED
UInt64 UNSIGNED, BIGINT UNSIGNED, BIT, SET

Syntax

Int32

Related

  • Int64
  • UInt32

Int64

A 64-bit signed integer. See the Int32 entry for the full documentation of the integer types.

Syntax

Int64

Related

  • Int32

Int8

A 8-bit signed integer. See the Int32 entry for the full documentation of the integer types.

Syntax

Int8

Related

  • Int32

IntervalDay

The family of data types representing time and date intervals. The resulting types of the INTERVAL operator.

Structure:

  • Time interval as an unsigned integer value.
  • Type of an interval.

Supported interval types:

  • NANOSECOND
  • MICROSECOND
  • MILLISECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • QUARTER
  • YEAR

For each interval type, there is a separate data type. For example, the DAY interval corresponds to the IntervalDay data type:

SELECT toTypeName(INTERVAL 4 DAY)
┌─toTypeName(toIntervalDay(4))─┐
│ IntervalDay                  │
└──────────────────────────────┘

Usage Remarks

You can use Interval-type values in arithmetical operations with Date and DateTime-type values. For example, you can add 4 days to the current time:

SELECT now() AS current_date_time, current_date_time + INTERVAL 4 DAY
┌───current_date_time─┬─plus(now(), toIntervalDay(4))─┐
│ 2019-10-23 10:58:45 │           2019-10-27 10:58:45 │
└─────────────────────┴───────────────────────────────┘

Also it is possible to use multiple intervals simultaneously:

SELECT now() AS current_date_time, current_date_time + (INTERVAL 4 DAY + INTERVAL 3 HOUR)
┌───current_date_time─┬─plus(current_date_time, plus(toIntervalDay(4), toIntervalHour(3)))─┐
│ 2024-08-08 18:31:39 │                                                2024-08-12 21:31:39 │
└─────────────────────┴────────────────────────────────────────────────────────────────────┘

And to compare values with different intervals:

SELECT toIntervalMicrosecond(179999999) < toIntervalMinute(3);
┌─less(toIntervalMicrosecond(179999999), toIntervalMinute(3))─┐
│                                                           1 │
└─────────────────────────────────────────────────────────────┘

Mixed-type Intervals

Intervals of mixed type, e.g. multiple hours and multiple minutes, can be created using INTERVAL 'value' <from_kind> TO <to_kind> syntax. The result is a tuple of two or more intervals.

Supported combinations:

Syntax String format Example
YEAR TO MONTH Y-M INTERVAL '2-6' YEAR TO MONTH
DAY TO HOUR D H INTERVAL '5 12' DAY TO HOUR
DAY TO MINUTE D H:M INTERVAL '5 12:30' DAY TO MINUTE
DAY TO SECOND D H:M:S INTERVAL '5 12:30:45' DAY TO SECOND
HOUR TO MINUTE H:M INTERVAL '1:30' HOUR TO MINUTE
HOUR TO SECOND H:M:S INTERVAL '1:30:45' HOUR TO SECOND
MINUTE TO SECOND M:S INTERVAL '5:30' MINUTE TO SECOND

Non-leading fields are validated per the SQL standard: MONTH 0-11, HOUR 0-23, MINUTE 0-59, SECOND 0-59.

SELECT INTERVAL '1:30' HOUR TO MINUTE;
┌─(toIntervalHour(1), toIntervalMinute(30))─┐
│ (1,30)                                     │
└────────────────────────────────────────────┘

An optional leading + or - sign applies to all components:

SELECT INTERVAL '+1:30' HOUR TO MINUTE;
-- this is equivalent to:
-- SELECT INTERVAL '1:30' HOUR TO MINUTE;
┌─(toIntervalHour(1), toIntervalMinute(30))─┐
│ (1,30)                                     │
└────────────────────────────────────────────┘

See Also

Syntax

IntervalDay

Related

  • IntervalSecond
  • IntervalMonth

IntervalHour

Represents an interval of hours; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalHour

Related

  • IntervalDay

IntervalMicrosecond

Represents an interval of microseconds; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalMicrosecond

Related

  • IntervalDay

IntervalMillisecond

Represents an interval of milliseconds; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalMillisecond

Related

  • IntervalDay

IntervalMinute

Represents an interval of minutes; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalMinute

Related

  • IntervalDay

IntervalMonth

Represents an interval of months; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalMonth

Related

  • IntervalDay

IntervalNanosecond

Represents an interval of nanoseconds; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalNanosecond

Related

  • IntervalDay

IntervalQuarter

Represents an interval of quarters; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalQuarter

Related

  • IntervalDay

IntervalSecond

Represents an interval of seconds; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalSecond

Related

  • IntervalDay

IntervalWeek

Represents an interval of weeks; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalWeek

Related

  • IntervalDay

IntervalYear

Represents an interval of years; used as the result of arithmetic on dates/times. See the IntervalDay entry for full documentation.

Syntax

IntervalYear

Related

  • IntervalDay

UInt128

A 128-bit unsigned integer. See the Int32 entry for the full documentation of the integer types.

Syntax

UInt128

Related

  • Int32

UInt16

A 16-bit unsigned integer. See the Int32 entry for the full documentation of the integer types.

Syntax

UInt16

Related

  • Int32

UInt256

A 256-bit unsigned integer. See the Int32 entry for the full documentation of the integer types.

Syntax

UInt256

Related

  • Int32

UInt32

A 32-bit unsigned integer. See the Int32 entry for the full documentation of the integer types.

Syntax

UInt32

Related

  • Int32

UInt64

A 64-bit unsigned integer. See the Int32 entry for the full documentation of the integer types.

Syntax

UInt64

Related

  • Int32

UInt8

A 8-bit unsigned integer. See the Int32 entry for the full documentation of the integer types.

Syntax

UInt8

Related

  • Int32