public inbox for [email protected]  
help / color / mirror / Atom feed
From: Christophe Pettus <[email protected]>
To: Rich Shepard <[email protected]>
Cc: [email protected]
Subject: Re: Gaps in PK sequence numbers [RESOLVED]
Date: Mon, 10 Jun 2024 18:21:59 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>



> On Jun 10, 2024, at 18:10, Rich Shepard <[email protected]> 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.





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Gaps in PK sequence numbers [RESOLVED]
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox