Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGo5f-00HPWV-1B for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 23:06:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGo5c-00HLp4-GE for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 23:06:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGo5c-00HLoS-4v for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 23:06:13 +0000 Received: from smtp110.ord1d.emailsrvr.com ([184.106.54.110]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGo5a-0010ZT-OZ for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 23:06:12 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp6.relay.ord1d.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id DF02FE025F; Mon, 10 Jun 2024 19:06:06 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: Gaps in PK sequence numbers From: Christophe Pettus In-Reply-To: <35fd10ab-5f7f-7a57-9cc5-c03d81476d13@appl-ecosys.com> Date: Mon, 10 Jun 2024 16:05:30 -0700 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <35fd10ab-5f7f-7a57-9cc5-c03d81476d13@appl-ecosys.com> To: Rich Shepard X-Mailer: Apple Mail (2.3774.600.62) X-Classification-ID: 085d013b-c0f7-434d-8feb-0e2204ed8dc8-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 10, 2024, at 15:57, Rich Shepard = 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.