Re: serial columns & loads misfeature?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: serial columns & loads misfeature?
Дата
Msg-id 5982.1025291019@sss.pgh.pa.us
обсуждение исходный текст
Ответ на serial columns & loads misfeature?  (Kevin Brannen <kevinb@nurseamerica.net>)
Список 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 по дате отправления:

Предыдущее
От: Manfred Koizar
Дата:
Сообщение: Re: serial columns & loads misfeature?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: serial columns & loads misfeature?