INT

On this page Carat arrow pointing down
Warning:
As of April 30, 2020, CockroachDB v2.1 is no longer supported. For more details, refer to the Release Support Policy.

CockroachDB supports various signed integer data types.

Note:

For instructions showing how to auto-generate integer values (e.g., to auto-number rows in a table), see this FAQ entry.

Names and Aliases

Name Allowed Width Aliases
INT 64-bit INTEGER
INT8
INT64
BIGINT
INT4 32-bit None
INT2 16-bit SMALLINT

Syntax

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

Size

The different integer types place different constraints on the range of allowable values, but all integers are stored in the same way regardless of type. Smaller values take up less space than larger ones (based on the numeric value, not the data type).

Examples

icon/buttons/copy
> CREATE TABLE ints (a INT PRIMARY KEY, b SMALLINT);
icon/buttons/copy
> SHOW COLUMNS FROM ints;
+-------------+-----------+-------------+----------------+-----------------------+-------------+
| column_name | data_type | is_nullable | column_default | generation_expression |   indices   |
+-------------+-----------+-------------+----------------+-----------------------+-------------+
| a           | INT       |    false    | NULL           |                       | {"primary"} |
| b           | SMALLINT  |    true     | NULL           |                       | {}          |
+-------------+-----------+-------------+----------------+-----------------------+-------------+
(3 rows)
icon/buttons/copy
> INSERT INTO ints VALUES (1, 32);
INSERT 1
icon/buttons/copy
> SELECT * FROM ints;
+---+----+
| a | b  |
+---+----+
| 1 | 32 |
+---+----+
(1 row)

Supported casting and 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). This is a CockroachDB experimental feature which may be changed without notice.
TIMESTAMP Converts to seconds since the Unix epoch (Jan. 1, 1970). This is a CockroachDB experimental feature which may be changed without notice.
INTERVAL Converts to microseconds
STRING ––

See also

Data Types


Yes No
On this page

Yes No