PostgreSQL: Create an auto incrementing Primary Key using a Custom Sequence

In this post, I am creating an auto increment PRIMARY KEY using a custom sequence of the PostgreSQL.

PostgreSQL already provides two data types for auto increment id, serial (4 bytes) & bigserial (8 bytes).
When we apply serial or bigserial to the particular column, internally it creates a default sequence object for that column and automatically it generates auto increment value for that column.

We can also create custom sequence object in the PostgreSQL and it also requires in some situation where we do not want to use default sequence value.

First, Create a sequence object:Starting with 100 and increment by 10

Create sample table:

Use this sequence object and Insert sample data:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Sort by:   newest | oldest | most voted
Bruno Felipe

Nice post, thanks for sharing it