postgresql
  1. postgresql-bigint

BIGINT - (PostgreSQL Data Types)

In PostgreSQL, BIGINT is a numeric data type used to store integers with a maximum value of 9223372036854775807. In this tutorial, we'll take a closer look at the BIGINT data type in PostgreSQL, including its syntax, example, output, explanation, use, important points, and a summary of the topic.

Syntax

The syntax for defining a BIGINT column in a PostgreSQL table is as follows:

column_name BIGINT

Example

Let's create a table named users with a BIGINT column named id and insert some data into it:

CREATE TABLE users (
   id BIGINT,
   name TEXT,
   email TEXT
);

INSERT INTO users (id, name, email)
VALUES (9223372036854775807, 'John Doe', 'john@example.com');

In this example, we created a table named users with a BIGINT column named id and inserted a record into the table with the highest possible BIGINT value of 9223372036854775807.

Explanation

The BIGINT data type is used to store whole numbers with a maximum value of 9223372036854775807 and a minimum value of -9223372036854775808. It requires 8 bytes of storage compared to a regular INTEGER, which requires 4 bytes.

It is commonly used when you need to store large integers that exceed the range of INTEGER data types. This data type is also used when you need to ensure that the integer values stored in the column are large enough to accommodate future growth in your application.

Use

The BIGINT data type is commonly used in financial, scientific, and engineering applications where large numeric values are required. It is useful for storing phone numbers, account numbers, social security numbers, and other types of unique identifiers that require a large number of digits.

Important Points

  • BIGINT is an 8-byte integer data type.
  • It can store whole numbers with a maximum value of 9223372036854775807 and a minimum value of -9223372036854775808.
  • When defining a BIGINT column in a PostgreSQL table, you should ensure that the values to be stored in the column are actually too big to fit into the INTEGER column.
  • If you try to insert a value that exceeds the maximum value of BIGINT or is less than the minimum value of BIGINT, PostgreSQL will return an error.

Summary

In this tutorial, we discussed the BIGINT data type in PostgreSQL. We covered its syntax, example, output, explanation, use, and important points. We learnt that BIGINT is a data type typically used when storing very large integers that cannot fit into the range of INTEGER data types. With this knowledge, you can now use the BIGINT data type to store large integers with up to 19 digits in your PostgreSQL database.

Published on: