?
Solved

Postgresql change auto-increment

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

Expert Comment

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

0
 

Author Comment

by:chiabp
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
0
 
LVL 10

Accepted Solution

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

Check the postgresql sequence documentation at:
http://www.postgresql.org/docs/8.2/interactive/functions-sequence.html

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

0
 
LVL 62

Expert Comment

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

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