public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: Rich Shepard <[email protected]>
Cc: [email protected]
Subject: Re: Gaps in PK sequence numbers
Date: Mon, 10 Jun 2024 16:03:50 -0700
Message-ID: <CAKFQuwboV8qvZrGWb+TOsNVYXzf=j=gE3fYMYFoNg2JT2_0YqA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On Mon, Jun 10, 2024 at 3:57 PM Rich Shepard <[email protected]>
wrote:

>
> I found a web page that explains how to find the gaps in a sequence, yet I
> want to understand why nextval() doesn't begin with the max(FK)+1 value.
>

For efficiency the only thing used to determine the next value of a
sequence is the stored value of the last sequence value issued.  Where that
value may have been used, in a table as a PK or some other purpose, does
not enter into it.  Using a sequence as a default does indeed become
problematic if you don't use it exclusively.  If you do use it exclusively
usually you just set the last value to be the maximum needed and use it
going forward.  The numbers from deleted rows simply remain missing in the
table.

David J.


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
  In-Reply-To: <CAKFQuwboV8qvZrGWb+TOsNVYXzf=j=gE3fYMYFoNg2JT2_0YqA@mail.gmail.com>

* 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