Open In App

PostgreSQL – Data Types

In this article, we will look into the various data types available in PostgreSQL. The following data types are supported by PostgreSQL: 

Now let’s get an overview of the above-mentioned data types. 



Boolean:

In PostgreSQL, the “bool” or”boolean” keyword is used to initialize a Boolean data type. These data types can hold true, false, and null values. A boolean data type is stored in the database according to the following:

When queried for these boolean data types are converted and returned according to the following:



Characters :

PostgreSQL has three character data types namely, CHAR(n), VARCHAR(n), and TEXT

Numeric:

PostgreSQL has 2 types of numbers namely, integers and floating-point numbers. 

1. Integer: 

2. Floating-point number: 

Temporal data type:

This data type is used to store date-time data. PostgreSQL has 5 temporal data type: 

Arrays:

In PostgreSQL, an array column can be used to store an array of strings or an array of integers etc. It can be handy when storing data likes storing days of months, a year, or even a week, etc. 

JSON:

PostgreSQL supports 2 types of JSON types namely JSON and JSONB(Binary JSON). The JSON data type is used to store plain JSON data that get parsed every time it’s called by a query. Whereas the JSONB data type is used to store JSON data in a binary format. It is one hand makes querying data faster whereas slows down the data insertion process as it supports indexing of table data.

UUID:

The UUID data type allows you to store Universal Unique Identifiers defined by RFC 4122. The UUID values guarantee a better uniqueness than SERIAL and can be used to hide sensitive data exposed to the public such as values of id in URL. 

The UUID stands for Unique Universal Identifiers. These are used to give a unique ID to a data that is unique throughout the database. The UUID data type are used to store UUID of the data defined by RFC 4122. These are generally used to protect sensitive data like credit card informations and is better compared to SERIAL data type in the context of uniqueness.

Special data types:

In addition to the primitive data types, PostgreSQL also supports some special data types that are related to network or geometric. These special data types are listed below: 

Article Tags :