From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(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 |
Date: | 2024-06-10 23:03:50 |
Message-ID: | CAKFQuwboV8qvZrGWb+TOsNVYXzf=j=gE3fYMYFoNg2JT2_0YqA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Jun 10, 2024 at 3:57 PM Rich Shepard <rshepard(at)appl-ecosys(dot)com>
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Christophe Pettus | 2024-06-10 23:05:30 | Re: Gaps in PK sequence numbers |
Previous Message | Thomas Munro | 2024-06-10 22:59:28 | Re: libpq v17 PQsocketPoll timeout is not granular enough |