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 1sHshU-00BLvt-Bn for pgsql-general@arkaria.postgresql.org; Thu, 13 Jun 2024 22:13:44 +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 1sHshR-008iBq-Dt for pgsql-general@arkaria.postgresql.org; Thu, 13 Jun 2024 22:13:42 +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 1sHshR-008iBh-2S for pgsql-general@lists.postgresql.org; Thu, 13 Jun 2024 22:13:41 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHshP-001XFp-Gg for pgsql-general@lists.postgresql.org; Thu, 13 Jun 2024 22:13:41 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 1E6C42A2B7C for ; Thu, 13 Jun 2024 15:13:37 -0700 (PDT) Date: Thu, 13 Jun 2024 15:13:37 -0700 (PDT) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Reset sequence to current maximum value of rows In-Reply-To: <4f319e27-0e54-40dd-888f-1e4c856a1b02@aklaver.com> Message-ID: References: <387fa6c2-5de-f24-d522-46282597703@appl-ecosys.com> <1b139d9a-b95f-f7c8-52fb-9d7442c69ad9@appl-ecosys.com> <97d69b9-48de-3bd4-95d-df5614ff44a@appl-ecosys.com> <4f319e27-0e54-40dd-888f-1e4c856a1b02@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 13 Jun 2024, Adrian Klaver wrote: > Not with: > > Table "public.companies" > > [...] > Indexes: > "organizations_pkey" PRIMARY KEY, btree (company_nbr) > > That would throw duplicate key errors. > > Are you sure that you did not do this on the contacts table as the company FK > back to companies? Adrian, Yes, I'm sure. Early yesterday I did get duplicate key errors. That's when I looked on stackexchange to learn how to reset the sequence's max value to the value of the number of rows in the table. Not only did my attempt to add a single new company to the companies table change all company names in that one industry to the new name, but I just discovered that it changed all rows in that column to the new company name: company_nbr | company_name -------------+------------------------------------------------- 1 | Markowitz Herbold PC 2 | Markowitz Herbold PC 3 | Markowitz Herbold PC 4 | Markowitz Herbold PC 5 | Markowitz Herbold PC 6 | Markowitz Herbold PC 7 | Markowitz Herbold PC 8 | Markowitz Herbold PC 9 | Markowitz Herbold PC 10 | Markowitz Herbold PC 11 | Markowitz Herbold PC 12 | Markowitz Herbold PC 13 | Markowitz Herbold PC 14 | Markowitz Herbold PC 15 | Markowitz Herbold PC 16 | Markowitz Herbold PC 17 | Markowitz Herbold PC 18 | Markowitz Herbold PC 19 | Markowitz Herbold PC 20 | Markowitz Herbold PC 22 | Markowitz Herbold PC 23 | Markowitz Herbold PC --More-- So now I need to extract the companies table data from my 2024-06-10 backup and use that to update the entire table. Sigh. There are 2101 rows in that table and I must have forgotten to specify industry for that one new addition. Not like me to do so, but it's the only explanation I have. It might be quicker for me to restore the entire database from that backup and then insert all new table rows since I have saved all the scripts. Regards, Rich