Re: STARTING SERIAL / BIGSERIAL FIELDS FROM 1. - Mailing list pgsql-novice

From Michael Wood
Subject Re: STARTING SERIAL / BIGSERIAL FIELDS FROM 1.
Date
Msg-id 5a8aa6680907201258mc336287g708bd98793db73fe@mail.gmail.com
Whole thread Raw
In response to STARTING SERIAL / BIGSERIAL FIELDS FROM 1.  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List pgsql-novice
2009/7/20 JORGE MALDONADO <jorgemal1960@gmail.com>:
> How can a serial or bigserial field start from 1 again?
> I need to manually remove all the records from a table and I need these kind
> of fields to start from 1 once again.

If you use pg_dump on the database you should see something like this:

SELECT pg_catalog.setval('table_column_seq', 123456789, true);

That means that the last value will be set to 123456789 if you restore
using this dump.

You can do something like this, except that you can't set it to 0, so
you need to do this instead:

SELECT pg_catalog.setval('table_column_seq', 1, false);

Then the next value used would be 1.

--
Michael Wood <esiotrot@gmail.com>

pgsql-novice by date:

Previous
From: Jure Kobal
Date:
Subject: Re: STARTING SERIAL / BIGSERIAL FIELDS FROM 1.
Next
From: Mike
Date:
Subject: Re: How to insert data from a text file