2
votes

Before you mark this a duplicate. I found this answer on another thread and having difficulties making it work.

From psql I see my table:

\d people

Table:

Column       |                   Type                |                        Modifiers
---------------+----------------------------------+-----------------------------------------------------------------------
id                 |               integer                 |       not null default nextval('people_id_seq'::regclass)

Code I tried which seems to do nothing...

ALTER SEQUENCE people_id_seq RESTART 1000

How do I make the primary key start from 1000?

2
You can try SELECT setval('people_id_seq', 999); - Joseph B
try also if this can help [see this][1] [1]: stackoverflow.com/questions/12076741/… - bumbumpaw
"in another thread". Link? - Craig Ringer
"seems to do nothing"? Well, what happens before/after? How do you determine what it does/doesn't do? Show some code. - Craig Ringer

2 Answers

6
votes

The following query would set the sequence value to 999. The next time the sequence is accessed, you would get 1000.

SELECT setval('people_id_seq', 999);

Reference:

Sequence Manipulation Functions on PostgreSQL Manual

2
votes

Why are you declaring your id like that ?

I mean, I would do the following :

create table people( id serial, constraint primaryKeyID primary key(id));

And now if you want to start your sequence from 1000, your alter query will work.

alter sequence people_id_seq restart 1000