Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a postgres table that contains data where the id has been set by the code that injected the data. So lets say the id is 0..49.

How can I instruct postgres to start with 50 on the id column for the next insert?

share|improve this question
up vote 1 down vote accepted

If you want to happen it automatically (I mean, without the application doing that), you have to create a sequence:

CREATE SEQUENCE some_table_pk_seq START 50;

Then change the column to use this as a default:

ALTER TABLE some_table
ALTER COLUMN id SET DEFAULT nextval('some_table_pk_seq'::regclass);

And that's it. Remember that the default will be used only if you don't pass a value to the given column in your INSERT statements.

share|improve this answer
To do it after sequence (or serial) creation: setval('some_table_pk_seq'::regclass, 50); – Kirk Roybal Dec 20 '13 at 15:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.