#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Maximum Autoincrement Value


    What is the best way to cause an autoincrement column to roll after it reaches a specific maximum like 32768. I don't want to just define the column type to be smallint, but want the value to roll back to 1 and hole-fill if we reach the maximum.
    Thanks for any ideas!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,785
    Rep Power
    348
    A quick look into the manual for the CREATE SEQUENCE statement reveals:
    Originally Posted by Postgres manual
    The CYCLE option allows the sequence to wrap around when the maxvalue or minvalue has been reached by an ascending or descending sequence respectively. If the limit is reached, the next number generated will be the minvalue or maxvalue, respectively.
    Taken from: http://www.postgresql.org/docs/current/static/sql-createsequence.html

    Please read the manual the next time before posting such a trivial question.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

IMN logo majestic logo threadwatch logo seochat tools logo