Re: how to reset the sequences of SERIAL vars?

From: "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: how to reset the sequences of SERIAL vars?
Date: 2002-11-01 10:18:57
Message-ID: 3DC2A269.24192.914266C@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1 Nov 2002 at 10:59, Bruno Boettcher wrote:
> when inserting from backup the tables are filled with all fields, this
> means alos those defined as serial, but without using nextval...
>
> this means that the sequences for those vars are out of synch with the
> table after the backup...
>
> now there was a sequence to set this up and runnign again, but i cna't
> find it in my papers anymore, so if someone could kindly point me out
> on how to set up the correct values un the sequence i will be really
> grateful.

From createsequence.html in postgresql manual

---------------------------------------
Update the sequence value after a COPY FROM:

BEGIN;
COPY distributors FROM 'input_file';
SELECT setval('serial', max(id)) FROM distributors;
END;
---------------------------------------

Also look at functions-sequence.html for more reference.

HTH

Bye
Shridhar

--
Barometer, n.: An ingenious instrument which indicates what kind of weather we
are having. -- Ambrose Bierce, "The Devil's Dictionary"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jens-Christian Skibakk 2002-11-01 10:19:02 Re: limit
Previous Message Martijn van Oosterhout 2002-11-01 10:11:53 Re: how to reset the sequences of SERIAL vars?