Re: Gaps in PK sequence numbers [RESOLVED]

Поиск
Список
Период
Сортировка
От Christophe Pettus
Тема Re: Gaps in PK sequence numbers [RESOLVED]
Дата
Msg-id 88E9C97A-E616-4162-9CAB-64C98C5620B6@thebuild.com
обсуждение исходный текст
Ответ на Re: Gaps in PK sequence numbers [RESOLVED]  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: Gaps in PK sequence numbers [RESOLVED]
Список pgsql-general

> On Jun 10, 2024, at 18:10, Rich Shepard <rshepard@appl-ecosys.com> wrote:
> Thanks, Christophe. Is there a way to reset the sequence to the maximum
> number +1? I don't recall seeing this in the postgres docs but will look
> again.

The sequence functions are documented here:

    https://www.postgresql.org/docs/current/functions-sequence.html

setval is the function you want.  You can use a SELECT so you don't have to copy values around:

    select setval('t_pk_seq', (select max(pk) from t));

That form of setval() sets the sequence so that the next value will be one more than the value you set it to, so you
don'thave to do max()+1 there. 


В списке pgsql-general по дате отправления:

Предыдущее
От: Rich Shepard
Дата:
Сообщение: Re: Gaps in PK sequence numbers
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Gaps in PK sequence numbers [RESOLVED]