Open In App

PostgreSQL major versions

Last Updated : 26 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

PostgreSQL is a leading open-source relational database management system that releases major versions annually, introducing essential features and performance improvements. Each major version often includes significant changes.

In this article, we will learn PostgreSQL major versions and how to use them in terms of concept and syntax, as well as give examples.

What Are PostgreSQL Major Versions?

  • PostgreSQL development strategy revolves around major version releases that introduce new features, optimizations and enhancements.
  • Each major version often includes significant changes, including breaking API compatibility with previous versions.

Identifying PostgreSQL Major Versions:

PostgreSQL versions follow a standard numbering system, with the first two numbers representing the major version. For example:

  • PostgreSQL 13.0
  • PostgreSQL 14.0

These major versions are released annually, introducing new functionalities, security improvements, and performance enhancements.

Syntax for Checking PostgreSQL Version:

SELECT version();

To identify the PostgreSQL version running on your system, use the following query:

Example 1: Checking PostgreSQL Version

When working with multiple PostgreSQL versions, it is crucial to know which version you are using. The following query provides detailed information about the running PostgreSQL instance:

Query:

SELECT version();

Output:

PostgreSQL-version
PostgreSQL version

Explanation:

This query retrieves detailed information about the PostgreSQL system, including the version number, release date, and server details. It helps in identifying the specific PostgreSQL version and the environment where the database is running.

Example 2: JSONB Data Type in PostgreSQL 9.4+

Starting with PostgreSQL 9.4, the JSONB (Binary JSON) data type was introduced. It is more efficient than the traditional JSON type because it supports additional indexing options, making querying and searching faster.

Query:

-- Create a table with JSONB data type

CREATE TABLE orders (

order_id serial PRIMARY KEY,

order_details JSONB

);

Explanation:

This is an SQL command that defines a table called orders containing a column in JSONB format. Everything can be stored in this column as well as JSON fields can be indexed for better query response times.

Example 3: Table Partitioning in PostgreSQL 11+

One of the measures explain by Virtuoso is called table partitioning, and it divides a very large table into several smaller sub-tables. Another major improvement of PostgreSQL is the partitioning that received a native support beginning with version 11, although the functions and the syntax used in that version were improved and simplified.

Query:

-- Creating a partitioned table

CREATE TABLE sales (

sale_id serial PRIMARY KEY,

sale_date date NOT NULL,

sale_amount numeric

) PARTITION BY RANGE (sale_date);


-- Creating partitions

CREATE TABLE sales_2023 PARTITION OF sales

FOR VALUES FROM ('2023-01-01') TO ('2024-01-01');

Explanation:

  • The first query creates a partitioned table sales that partitions data based on the sale_date column.
  • The second query creates a partition for data corresponding to the year 2023. This method helps in organizing time-series data efficiently.

Conclusion

PostgreSQL’s major versions contain the crucial enhancements and new functions that affect the work of the database. Every release contains changes that are not backward compatible. It is important to understand how to identify and work with these versions so as to facilitate easy management of the database systems and achieve best results.


Next Article
Article Tags :

Similar Reads