What Is BIGINT Data Type in PostgreSQL?

//

Angela Bailey

The BIGINT data type in PostgreSQL is used to store large whole numbers that may exceed the range of the INTEGER data type. It can store numbers from -9223372036854775808 to 9223372036854775807.

Usage

To define a column with the BIGINT data type, you can use the following syntax:

CREATE TABLE table_name (
    column_name BIGINT
);

You can also use the BIGINT data type as a primary key or part of a composite primary key:

CREATE TABLE table_name (
    column1 BIGINT PRIMARY KEY,
    column2 INTEGER,
    ..
);

Size and Range

The BIGINT data type takes up 8 bytes of storage and allows you to store values ranging from -9223372036854775808 to 9223372036854775807. This means it can handle extremely large numbers.

Example:

CREATE TABLE employees (
   employee_id BIGINT PRIMARY KEY,
   first_name VARCHAR(50),
   last_name VARCHAR(50),
   salary DECIMAL(10, 2)
);

Operations on BIGINT Data Type

You can perform various operations on columns with the BIGINT data type, such as:

  • Addition:
  •   SELECT column1 + column2 FROM table_name;
      
  • Subtraction:
  •   SELECT column1 - column2 FROM table_name;
      
  • Multiplication:
  •   SELECT column1 * column2 FROM table_name;
      
  • Division:
  •   SELECT column1 / column2 FROM table_name;
      
  • Modulo:
  •   SELECT column1 % column2 FROM table_name;
      

Conclusion

The BIGINT data type in PostgreSQL provides a way to store large whole numbers. It is useful when you need to work with numbers that exceed the range of the INTEGER data type. By using the BIGINT data type, you can ensure that your database can handle extremely large numbers without any loss of precision.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy