How to set up manually the next value of auto_increment? How to set up manually the next value of auto_increment? postgresql postgresql

How to set up manually the next value of auto_increment?


http://www.postgresql.org/docs/current/static/functions-sequence.html

select setval('sequence-name', <new-value>);

You can get the sequence name from the the table definition:

id       | integer                | not null default nextval('id_seq'::regclass)

In this case the sequence is named 'id_seq'

Edit (10x to @Glenn):

SELECT setval('id_seq', max(id)) FROM table;


I think there is a simpler way:

ALTER SEQUENCE "seq_product_id"  RESTART WITH 10