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 1sGnxD-00HO9R-FG for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 22:57:32 +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 1sGnxB-00HAya-RD for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 22:57:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGnxB-00HAyS-GB for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 22:57:30 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGnxA-000hUN-0A for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 22:57:29 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 8A80A2A2B7C for ; Mon, 10 Jun 2024 15:57:26 -0700 (PDT) Date: Mon, 10 Jun 2024 15:57:26 -0700 (PDT) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Gaps in PK sequence numbers Message-ID: <35fd10ab-5f7f-7a57-9cc5-c03d81476d13@appl-ecosys.com> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Over the years I've deleted rows from tables leaving gaps in the PK sequence numbers. I've now learned that using nextval('sequencename') finds those gaps and tells me that the value after the gap is already assigned. 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. 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? TIA, Rich