Re: Gaps in PK sequence numbers [RESOLVED]

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Gaps in PK sequence numbers [RESOLVED]
Date: 2024-06-11 01:21:59
Message-ID: 88E9C97A-E616-4162-9CAB-64C98C5620B6@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Jun 10, 2024, at 18:10, Rich Shepard <rshepard(at)appl-ecosys(dot)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't have to do max()+1 there.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2024-06-11 01:23:58 Re: Gaps in PK sequence numbers [RESOLVED]
Previous Message Rich Shepard 2024-06-11 01:13:55 Re: Gaps in PK sequence numbers