Re: serial columns & loads misfeature? - Mailing list pgsql-general

From Tom Lane
Subject Re: serial columns & loads misfeature?
Date
Msg-id 5982.1025291019@sss.pgh.pa.us
Whole thread Raw
In response to serial columns & loads misfeature?  (Kevin Brannen <kevinb@nurseamerica.net>)
List pgsql-general
Kevin Brannen <kevinb@nurseamerica.net> writes:
> I was expecting the system to realize new "keys" had been inserted, and
> so when the "nextval" that implicitly happens on a serial field is run,
> it would "know" that it was too small and return "max(s)+1".

It does not, and I'm not convinced that it should.  Manual insertion
of values into an autonumbering column seems like, well, a manual
operation.  If you're going to bypass the autonumbering then you should
also be responsible for setting the sequence counter to whatever you
want it to be afterwards.

> I realize I can fix this by writting a Perl/DBI script to read the list
> of sequences, and do [conceptually]:

The usual locution is just

    select setval('seqname', (select max(col) + 1 from table));

            regards, tom lane



pgsql-general by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: serial columns & loads misfeature?
Next
From: Tom Lane
Date:
Subject: Re: serial columns & loads misfeature?