Re: how to best resync serial columns

From: Erik Jones <ejones(at)engineyard(dot)com>
To: "Brent Wood" <b(dot)wood(at)niwa(dot)co(dot)nz>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to best resync serial columns
Date: 2008-11-11 04:19:33
Message-ID: A68280DC-D93C-404E-A352-52B5939667F8@engineyard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Nov 10, 2008, at 6:48 PM, Brent Wood wrote:

> Hi,
>
> I have a number of tables with serial columns as a primary key.
>
> I'm looking to add lots of records via copy, but should reset the
> serial counters to the appropriate value after this.
>
> Is there a simple way to do this, or do I just update the last_value
> column in each seq table to the max(id) from the relevant table.

You shouldn't edit sequence table directly. To set a sequence's value
you should use the setval(seqname, seqval) function like so:

SELECT setval('some_seq', 1000);

Erik Jones, Database Administrator
Engine Yard
Support, Scalability, Reliability
866.518.9273 x 260
Location: US/Pacific
IRC: mage2k

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Josh Williams 2008-11-11 05:01:17 Re: ordered pg_dump
Previous Message Greg Smith 2008-11-11 04:15:49 Re: Current log files when rotating?