The INT data type stores 64-bit signed integers, that is, whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

To auto-generate globally unique integers, use the SERIAL data type.

Aliases

In CockroachDB, the following are aliases for INT:

  • SMALLINT
  • INTEGER
  • INT8
  • INT64
  • BIGINT

Syntax

A constant value of type INT can be entered as a numeric literal. For example: 42, -1234 or 0xCAFE.

Size

An INT column supports values up to 8 bytes in width, but the total storage size is likely to be larger due to CockroachDB metadata.

CockroachDB does not offer multiple integer types for different widths; instead, our compression ensures that smaller integers use less disk space than larger integers.

Examples

> CREATE TABLE ints (a INT PRIMARY KEY, b SMALLINT, c INTEGER);

> SHOW COLUMNS FROM ints;
+-------+------+-------+---------+
| Field | Type | Null  | Default |
+-------+------+-------+---------+
| a     | INT  | false | NULL    |
| b     | INT  | true  | NULL    |
| c     | INT  | true  | NULL    |
+-------+------+-------+---------+
> INSERT INTO ints VALUES (11111, 22222, 33333);

> SELECT * FROM ints;
+-------+-------+-------+
|   a   |   b   |   c   |
+-------+-------+-------+
| 11111 | 22222 | 33333 |
+-------+-------+-------+

Supported Casting & Conversion

INT values can be cast to any of the following data types:

Type Details
DECIMAL ––
FLOAT Loses precision if the INT value is larger than 2^53 in magnitude
BOOL 0 converts to false; all other values convert to true
DATE Converts to days since the Unix epoch (Jan. 1, 1970)
TIMESTAMP Converts to seconds since the Unix epoch (Jan. 1, 1970)
INTERVAL Converts to microseconds
STRING ––

See Also

Data Types



Yes No