INT4

INT4 is a data type in SQL that allows the storage of whole numbers, which can be both positive or negative. It is a 4-byte size variant of INT, meaning it can store numerical values from -2147483648 to 2147483647.

Example

CREATE TABLE test (
id INT4
);
INSERT INTO test (id) VALUES (1234);
SELECT * FROM test;

Output

id
-----
1234

Explanation

This demonstrates the creation of a table named ‘test’ with one column ‘id’ of INT4 type, insert a value into it and then retrieve that value. INT4 is a 4-byte integer data type in PostgreSQL.

Example

DECLARE @MyVariable INT;
SET @MyVariable = 10;
SELECT @MyVariable AS 'INT4';

Output

INT4
10

Explanation

The code block declares a variable @MyVariable as INT type and sets it to the number 10. Then, we use SELECT statement to output the value of the @MyVariable, which is labeled as ‘INT4’.

Example

CREATE TABLE employees (
ID INT(4),
NAME VARCHAR(20),
BIRTHDATE DATE
);
INSERT INTO employees (ID, NAME, BIRTHDATE) values (1234, 'John', TO_DATE('1990/01/01','YYYY/MM/DD'));

Output

SELECT * FROM employees;
ID | NAME | BIRTHDATE
-----|--------|-----------
1234 | John | 01-JAN-90

Explanation

In this example, a new table named ‘employees’ is created with three columns: ID, NAME, and BIRTHDATE. INT(4) is used to declare the ID column, which only allows up to four digits. A new record is inserted into the table, with the value 1234 in the ID field, demonstrating that the INT(4) declaration allows for this four digit integer. The output shows the result of a SELECT * FROM employees query, confirming that the new record has been successfully inserted.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.