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