Skip site navigation (1) Skip section navigation (2)

Re: STARTING SERIAL / BIGSERIAL FIELDS FROM 1.

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: STARTING SERIAL / BIGSERIAL FIELDS FROM 1.
Date: 2009-07-20 19:58:09
Message-ID: 5a8aa6680907201258mc336287g708bd98793db73fe@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
2009/7/20 JORGE MALDONADO <jorgemal1960(at)gmail(dot)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(at)gmail(dot)com>

In response to

pgsql-novice by date

Next:From: MikeDate: 2009-07-20 20:45:31
Subject: Re: How to insert data from a text file
Previous:From: Michael WoodDate: 2009-07-20 19:43:44
Subject: Re: how to ignore a column from pg_dump

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group