Is there a way to reset the primary key of a PostgreSQL table to start at 1 again on a populated table?
Right now it’s generating numbers from 1000000 and up. I want it all to reset and start to 1, keeping all my existing data intact.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See a better option here: https://stackoverflow.com/a/5272164/5190
Primary keys that autoincrement (i.e., columns with data type
serial primary key) are associated with a sequence. You can set the next value for any sequence using thesetval(<seqname>, <next_value>)function. Note that to actually execute the function by itself you need to useSELECT, like this:SELECT setval(<seqname>, <next_value>)The name of the auto created sequences when using serial are
<table>_<column>_seq