EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL BIGINT

PostgreSQL BIGINT

Priya Pedamkar
Article byPriya Pedamkar

Updated May 22, 2023

PostgreSQL BIGINT

Introduction to PostgreSQL BIGINT

PostgreSQL BIGINT is the numeric data type used in PostgreSQL to store integer type of values, we can store the integer type of value using bigint data type in PostgreSQL. The size of the bigint data type in PostgreSQL is 8 bytes, and the range of the bigint data type is -9223372036854775808 to 9223372036854775807. Bigint data type is very useful and important in PostgreSQL to store the large number of integer. Numeric data type in PostgreSQL contains the smallint, integer, and bigint, there are different storage size structure for every data type in PostgreSQL, smallint and integer contains different storage size.

ADVERTISEMENT
Popular Course in this category
POSTGRESQL Course Bundle - 5 Courses in 1 | 1 Mock Test

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax

Below is the syntax of the BIGINT data type:

Create table name_of_table (name_of_column1 data_type, name_of_column2 data_type, name_of_column3 data_type, …, name_of_columnN BIGINT);
Name_of_variable or name_of_column BIGINT;
Alter table name_of_tablealter columnname_of_column type bigint;

Below is the parameter description syntax of BIGINT data type in PostgreSQL:

  • Create table: We define the creation of a table in PostgreSQL by using the “CREATE TABLE” statement and specifying the column’s data type as “BIGINT”. We can create any table and define data type as bigint to the column.
  • Name of table: In PostgreSQL, we define the table name by specifying the column’s data type as “BIGINT”. We can define bigint data type to the column at the time of table creation. Also, we have defined the data type as bigint after table creation using alter command.
  • Name of column 1 to name of column N: This is defined as creating a column on the table and defined the bigint data type for the same.
  • Data type: We assign a data type to the table column at the time of table creation. We can define data type as per which data we are storing in the table.
  • Bigint: The data type “BIGINT” is used for the column at the time of table creation. Using bigint data type, we can store a larger number of integer in PostgreSQL.
  • Name of variable: This is nothing but the column name which we used at the time of table creation.
  • Alter table: The ALTER TABLE command in PostgreSQL is used to alter a table. With the ALTER command, we can change the data type of a column from one type to another.
  • Alter column: The ALTER COLUMN command in PostgreSQL is used to modify a column. By using the ALTER command, we can change the data type of the column from one type to another.
  • Type: When changing the data type using the ALTER TABLE command in PostgreSQL, we define the new data type for the column.

How BIGINT Data Type works in PostgreSQL?

  • If we want to store a large integer type value into the table, at the same time, we are using bigint data type in PostgreSQL.
  • Performance of the bigint data type is less compared to using smallint and integer data type. So while using bigint data type in PostgreSQL, we have a strong reason before using the same in our application.
  • We can change the data type from smallint or integer to bigint. But we cannot change the varchar data type into bigint directly it will issue an error that we cannot automatically cast the data type into bigint.
  • Below example shows that we can change the data type smallint or integer to bigint but cannot change from varchar data type to bigint directly.
  • In below first example, we have alter the column that we are changing the data type form int to bigint, we have successfully changed it to bigint because it is possible in PostgreSQL to change the numeric data type into the bigint.
  • In the second example, changing the data type is impossible because we cannot convert the varchar data type into the bigint data type directly.

Code:

ALTER TABLE test_int ALTER COLUMN id type bigint;
ALTER TABLE test_int ALTER COLUMN name type bigint;
\d+ test_int;

Output:

postgreSQL BIGINT 1

  • Bigint data type will consume large storage to store the data into the table. We can store the number of galaxy star or scientific constant using bigint data type in PostgreSQL.

Examples

Given below are the examples mentioned:

Example #1

Create a table using bigint data type.

  • Below example shows that create a table by using bigint data type in PostgreSQL.
  • We are creating a table name as bigint_test and define the bigint data type to the column name as id.

Code:

create table bigint_test (id bigint, name varchar, phone integer, addreess varchar);
\d+ bigint_test;

Output:

postgreSQL BIGINT 2

Example #2

Insert value into bigint data type column.

  • Below example shows that insert a value into the bigint data type column.

Code:

insert into bigint_test values (123456789012345, 'ABC', 1234567890, 'Mumbai');
insert into bigint_test values (1234567890123456, 'PQR', 1234567890, 'Mumbai');
select * from bigint_test;

Output:

Insert value

Example #3

Alter column to change the data type from integer to bigint.

  • Below is the example of alter column to change the data type from integer to bigint.
  • We are changing the phone column data type from integer to bigint.

Code:

ALTER TABLE bigint_test ALTER COLUMN phone type bigint;
\d+ bigint_test

Output:

Alter column to change data type from integer

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL BIGINT” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL Materialized Views
  2. PostgreSQL REINDEX
  3. hstore in PostgreSQL
  4. PostgreSQL round
ADVERTISEMENT
PROGRAMMING LANGUAGES Course Bundle - 54 Courses in 1 | 4 Mock Tests
338+ Hours of HD Videos
54 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
SELENIUM Course Bundle - 15 Courses in 1 | 9 Mock Tests
39+ Hours of HD Videos
15 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
IOT System Course Bundle - 7 Courses in 1
43+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
JENKINS Course Bundle - 6 Courses in 1
15+ Hour of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW