Re: [GENERAL] How to increment by hand a sequence number. - Mailing list pgsql-general

From Jose' Soares
Subject Re: [GENERAL] How to increment by hand a sequence number.
Date
Msg-id 36A49455.7A28742@sferacarta.com
Whole thread Raw
In response to How to increment by hand a sequence number.  (Valerio Santinelli <tanis@mediacom.it>)
List pgsql-general
Valerio Santinelli wrote:
>
> I've exported a table from an existing MSAccess database to my
> PostgreSQL db.
> I use a serial ID on the table and now I'm getting errors when I add a
> new entry in the table if i don't specify the ID by hand (which should
> be placed automatically by the db  since it's a serial).
>
> The exact error is this one:
>
>     Cannot insert a duplicate key into a unique index.
>
> I think I should set the "last_value" field in the sequence to my real
> last value aon the ID field of the table, but Idon't know how to do it.
> Is there anybody who can help me ?
>
> Thanks
>
> Valerio Santinelli
> tanis@mediacom.it

You may drop the sequence and then re-create it by specifying the start
as in:

   DROP SEQUENCE contatore;
   CREATE SEQUENCE contatore START 101;

Or if you desire you can increment the counter like this:

   SELECT NEXTVAL ('contatore');

Buon divertimento!
-Jose'-

pgsql-general by date:

Previous
From: Herouth Maoz
Date:
Subject: Re: [GENERAL] Another one! :) How to convert char(1) to boolean without re-exporting tables.
Next
From: Peter T Mount
Date:
Subject: Re: [GENERAL] Graphics Supported?