INT data type stores 32-bit integer data.
Syntax | INT or INTEGER |
Quick Example | CREATE TABLE t (c INT); |
Range | -231 to 231-1 (2 Gb) |
Storage Size | 4 bytes |
Synonyms | INT, INTEGER and INT4 |
Versions: PostgreSQL 9.x and 8.x
Related data types for INT/INTEGER in PostgreSQL:
SMALLINT | 16-bit Integer | -32768 to 32767 |
BIGINT | 64-bit Integer | -263 to 263-1 |
DECIMAL/NUMERIC | Fixed point | |
SERIAL | 32-bit Integer | Auto-increment (identity) |
BIGSERIAL | 64-bit Integer | Auto-increment (identity) |
INT/INTEGER data type in other databases:
Oracle:
NUMBER(10, 0) | Integer data | |
INT/INTEGER | ANSI/ISO Compatibility | Converted to NUMBER(38) |
SQL Server:
INT/INTEGER | -231 to 231-1 (2 Gb) |
TINYINT | 0 to 255 |
SMALLINT | -32768 to 32767 |
BIGINT | -263 to 263-1 |
MySQL:
INT/INTEGER [UNSIGNED] | Signed: -231 to 231-1 (2 Gb) | Unsigned: 0 to 232-1 (4 Gb) |
TINYINT [UNSIGNED] | Signed: -128 to 127 | Unsigned: 0 to 255 |
SMALLINT [UNSIGNED] | Signed: -32768 to 32767 | Unsigned: 0 to 65535 |
MEDIUMINT [UNSIGNED] | Signed: -215 to 215-1 (8,388,607) | Unsigned: 0 to 216-1 (16,777,215) |
BIGINT [UNSIGNED] | Signed: -263 to 263-1 | Unsigned: 0 to 264-1 |
Conversion of INT/INTEGER data type:
PostgreSQL:
CREATE TABLE t_int1 ( c1 INT, c2 INTEGER, c3 INT4 );
Oracle:
Oracle supports INT/INTEGER data type for compatibility with ANSI/ISO SQL, but it is converted to NUMBER(38) that can store up to 38 digits and significantly exceeds 32-bit range for ANSI/ISO INTEGER.
To preserve INTEGER range, you can convert it to NUMBER(10, 0):
CREATE TABLE t_int1 ( c1 NUMBER(10, 0), c2 NUMBER(10, 0), c3 NUMBER(10, 0) );
SQL Server
SQL Server supports INT/INTEGER data types but does not support their synonym INT4 that needs to be converted:
CREATE TABLE t_int1 ( c1 INT, c2 INTEGER, c3 INT );
MySQL:
MySQL supports INT/INTEGER data types including synonym INT4, so no any conversion is required:
CREATE TABLE t_int1 ( c1 INT, c2 INTEGER, c3 INT4 );