posgresql image

How To Change Sequence Last Value In Database PostgreSQL

Risqi Ahmad
May 12, 2023

PostgreSQL is a widely used database in web apps, mobile applications, and analytics applications. That’s why applications that require more complex data processing are better suited to using PostgreSQL.

When creating a table in the PostgreSQL database, we always set a sequence for its primary ID. When creating a table that contains data, often the sequence of ID numbers has already been used by previous data, resulting in conflicts. Therefore, it is necessary to adjust the sequence number according to the next available number. To set the sequence order to match the desired order, you can use the following command.

SELECT setval(‘sequence_name', 2, true); 

Or

SELECT setval(‘sequence_name', 2);

The next value will be 3.

That’s my tip for you if you encounter that problem, hopefully it will be helpful.

Thank you 😂🖐️.

--

--

Risqi Ahmad

I love to share about Web Development and Data Science