Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNbTo-0005yQ-77 for pgsql-general@arkaria.postgresql.org; Mon, 06 May 2019 11:08:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hNbTm-0000FB-6z for pgsql-general@arkaria.postgresql.org; Mon, 06 May 2019 11:08:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNbTl-0000F4-Em for pgsql-general@lists.postgresql.org; Mon, 06 May 2019 11:08:17 +0000 Received: from srv01.teladesign.ie ([2001:41c9:1:41d::10]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hNbTe-0001ju-7A for pgsql-general@lists.postgresql.org; Mon, 06 May 2019 11:08:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rodonnell.ie; s=exim; h=Subject:Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:To:Sender:Reply-To: Cc:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KdXqXKUEn0v11JB5StmMdCzINEoCnBulr4xSplraHGs=; b=XaryOvI/WNgzTWeKpPUBNZANHM 0SK8l5oYRoWM/681Wv9uWa9l8nHHNtEo3SV1ayNcqJwifeSJKFz83+cAzQQSDHCHP4HoJO+eMMtcT JMok19Z+Pw6IJgses3AxiVX3b8E7qAtVnavVoFOuknOZkAVEu7ClBFAkNc1aOKk4ofHo=; Received: from [89.127.18.233] (helo=[192.168.15.91]) by srv01.teladesign.ie with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1hNbTY-000230-Vo; Mon, 06 May 2019 12:08:05 +0100 To: Arup Rakshit , pgsql-general@lists.postgresql.org References: From: Ray O'Donnell Message-ID: Date: Mon, 6 May 2019 12:08:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 89.127.18.233 X-SA-Exim-Mail-From: ray@rodonnell.ie X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on srv01.teladesign.ie X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: duplicate key value violates unique constraint "chinese_price_infos_pkey" X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on srv01.teladesign.ie) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/05/2019 12:05, Arup Rakshit wrote: > Every time I try to insert I get the error: > > docking_dev=# INSERT INTO "chinese_price_infos" ("item_code", > "price_cents", "unit", "description", "company_id", "created_at", > "updated_at") VALUES ('01GS10001', 6000, 'Lift', 'Shore Crane > Rental', '9ae3f8b8-8f3f-491c-918a-efd8f5100a5e', '2019-05-06 > 10:49:03.894725', '2019-05-06 10:49:03.894725'); ERROR: duplicate > key value violates unique constraint "chinese_price_infos_pkey" > DETAIL: Key (id)=(71165) already exists. docking_dev=# INSERT INTO > "chinese_price_infos" ("item_code", "price_cents", "unit", > "description", "company_id", "created_at", "updated_at") VALUES > ('01GS10001', 6000, 'Lift', 'Shore Crane Rental', > '9ae3f8b8-8f3f-491c-918a-efd8f5100a5e', '2019-05-06 10:49:03.894725', > '2019-05-06 10:49:03.894725'); ERROR: duplicate key value violates > unique constraint "chinese_price_infos_pkey" DETAIL: Key > (id)=(71166) already exists. > > Then I found: > > docking_dev=# SELECT MAX(id) FROM chinese_price_infos; max -------- > 128520 (1 row) > > docking_dev=# SELECT nextval('chinese_price_infos_id_seq'); nextval > --------- 71164 (1 row) > > Not sure how it is out of sync. How can I fix this permanently. I ran > vacuum analyze verbose; still same error. You can fix it by using setval() to set the sequence manually to something higher than the highest current id value in the table. However, it sounds as if something in the application code may be causing problems.... For example, is something generating id values without reference to the sequence? Ray. -- Raymond O'Donnell // Galway // Ireland ray@rodonnell.ie