Postgresql change auto-increment

Posted on 2008-11-11
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
    LVL 61

    Expert Comment

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


    Author Comment

    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

    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 61

    Expert Comment

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

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    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: ( 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.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now