Sunday , April 2 2023

PostgreSQL Sequence

In today’s article, I will tell you what postgresql sequence is and how it was created.

Sequence is a tool created for self -increasing numbers according to the values given. MSSQL, Oracle and Postgresql databases are also used.

Sequence sample usage is as follows.

CREATE SEQUENCE         Sequence name

INCREMENT                        how to increase

START                                    Start Value

MINVALUE                           minimum value

MAXVALUE                          Maximum value

CACHE                                   Cache value to be held

CYCLE                                    If the process to exceed the given maximum value is Cycle, when the maximum value exceeds, it starts from the value given to the start parameter again. No Cycle does not allow to start again.

OWNED BY                          Tablename, Columnname: Used to specify which table is used for the OWNED by parameter.

Sequence cannot be used when the table is deleted.

You can use the following command to create a sample sequence.

Let’s use Sequence in the table. Let’s create a two -column table called seqtable.

We have created the table and now let’s insert data using Sequence.

We inserted the data, but we used a different parameter here “Nextval” This parameter gives the next value. Let’s see how it was inserted by pulling select from our inserted table.

As seen above, we see that our data is inserted sequentially.

You can see the next number to be added with the help of the following command.


Faruk Erdem
Author: Faruk Erdem

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *