Re: Serial id not incrementing when manual ids are used, User Error? Bug? - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: Serial id not incrementing when manual ids are used, User Error? Bug?
Date
Msg-id 20041130052832.GA87521@winnie.fuhr.org
Whole thread Raw
In response to Serial id not incrementing when manual ids are used, User Error? Bug?  (mgalvin@nycap.rr.com)
List pgsql-bugs
On Mon, Nov 29, 2004 at 03:47:27PM -0500, mgalvin@nycap.rr.com wrote:

> So does post not update a SERIAL column sequence when id's are
> manually entered? Would I have to manually do a nextval on the seq
> when manually setting id's? Should't post know that i used an id
> number and use the next availible number, something like ( (the
> largest id number in the key) + increment_val )?

SERIAL is just a convenient way of creating an INTEGER column with
a default value.  If you provide a value for that column then the
default isn't used, so the INSERT never calls nextval() to increment
the sequence.

If you need to set some of the SERIAL column's values explicitly,
e.g., when importing data, then you can use ALTER SEQUENCE or
setval() when you're finished to change the sequence's value.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: 8.0 Beta-5 Linux PSQL Endless loop -- Followup
Next
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1333: vacuum full apparently fails to complete