Postgresql change auto-increment

Posted on 2008-11-11
Medium Priority
Last Modified: 2012-05-05
How to change postgresql auto-increment database field, similar to
"ALTER TABLE tbl AUTO_INCREMENT = 500" in MsSQL database?
Question by:chiabp
  • 2
LVL 62

Expert Comment

ID: 22929596
Undocomented nonstandard MS SQL feature is not implemented in PostgreSQL and is unlikely to ever be present in any database out there.


Author Comment

ID: 22929914
You mean there is no way for postgresql database to change the auto-increment number? I have search from internet, there is "setval()" function in postgresql, but I not sure how to use it, any ideas?

My purpose just simple to change my auto-number, example from 200 to 300

thank you
LVL 10

Accepted Solution

ivanovn earned 375 total points
ID: 22930818
You want to set the sequence to a different number?

Check the postgresql sequence documentation at:

In general you can use the code below to set the value.

-- Set the value of a sequence to 300
SELECT setval('schemaname.sequencename', 300);

Open in new window

LVL 62

Expert Comment

ID: 22932483
There is no documentation for MS SQL AUTO_INCREMENT=int table attribute.

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question