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
Date: Mon, 10 Jun 2024 16:05:30 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>



> On Jun 10, 2024, at 15:57, Rich Shepard <[email protected]> wrote:
> When I tried inserting new rows in the companies table psql told me that PK
> value 2310 already existed. Selecting max(PK) returned 2341. When entering
> multiple new rows is there a way to ignore gaps?

Strictly speaking, the sequence underlying nextval() has no idea what primary keys are or are not in use.  It's just a transaction-ignoring counter that increases with each nextval() call.  The only reason that you'd get duplicate key errors in this case are:

1. The sequence was reset to a different, lower value.
2. Rows were inserted that didn't use the sequence to select a primary key.








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: <[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