Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • PostgreSQL - Get Started
  • Install PostgreSQL
  • Connect to PostgreSQL DB
  • Create Database
  • Create Table
  • Copy Table
  • Drop Table
  • Drop Database
  • Truncate Table
  • ALTER Table
  • Rename Table
  • Rename Columns
  • Add Columns
  • Modify Column Type
  • Set Default Value of Column
  • Remove Columns
  • Add Constraints to Table
  • Insert Data
  • Upsert Data
  • Update Data
  • Delete Data
  • SELECT Statement
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • DISTINCT Clause
  • Inner Join
  • Left Outer Join
  • Right Outer Join
  • Full Outer Join
  • Self Join
  • Natural Join
  • Cross Join
  • LIMIT OFFSET Clause
  • GROUPING SETS
  • GROUPING() Function
  • GROUP BY CUBE
  • GROUP BY ROLLUP
  • Sub Query
  • ALL Operator
  • ANY Operator
  • UNION Operator
  • INTERSECT Operator
  • EXCEPT Operator
  • IS NULL Operator
  • BETWEEN Operator
  • LIKE Operator
  • CAST Operator
  • CASE Expressions
  • NULLIF()
  • COALESCE()
  • GREATEST(), LEAST()
  • WITH Queries (CTE)
  • Constraints
  • NOT NULL Constraint
  • Unique Constraint
  • Check Constraint
  • Primary Key
  • Foreign Key
  • Sequence
  • Serial Type
  • Identity Columns
  • Generated Columns
  • Data Types
  • Boolean Type
  • Character Type
  • Integer Type
  • Numeric Type
  • Date Type
  • Time Type
  • TimeStamp Type
  • Interval Type
  • Array Type
  • Json Type
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

PostgreSQL: Integer Data Type

PostgreSQL supports integer types: SMALLINT, INTEGER, and BIGINT to store whole number values. Here is a specification of each of these types.

NameStorageMinimum ValueMaximum Value
SMALLINT2 Bytes-32,768+32,767
INTEGER4 Bytes-2,147,483,648+2,147,483,647
BIGINT8 Bytes-9,223,372,036,854,775,808+9,223,372,036,854,775,807

Note that if you try to store value in each of the above types outside its defined range, Postgres will raise an error.

You can use SMALLINT to store small values like the number of students in class, the number of pages in a book, the age of people, etc.

Lets create Book table with pages column is defined as SMALLINT and insert some data to it.

Example:
CREATE TABLE Book (
	id SERIAL NOT NULL PRIMARY KEY,
	name VARCHAR(50) NOT NULL,
	pages SMALLINT NOT NULL
);

INSERT INTO Book(name, pages)
VALUES
	('The Power of Passion', 250),
	('How to Win Friends', 300);

Now let's fetch the data from Book table.

Now if you try to insert data in Book table with value of pages column beyond SMALLINT range, PostgreSQL will raise out of range error and will not allow to insert data

Example: Insert Large Value into SMALLINT
INSERT INTO book(name, pages)
VALUES ('Five Points Someone', 	33000);

The INTEGER type is used to store big whole numbers like the population of cities or countries. Note that short-form INT can also be used instead of INTEGER while defining the datatype of the column.

As the BIGINT type requires a lot more storage and decreases the performance of the database, so use it only if you ready need it.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.