pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ray O'Donnell <ray@rodonnell.ie>
To: Arup Rakshit <ar@zeit.io>
To: pgsql-general@lists.postgresql.org
Subject: Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"
Date: Mon, 6 May 2019 12:08:03 +0100
Message-ID: <a674bada-cfba-ee76-12ea-5d652f750e38@rodonnell.ie> (raw)
In-Reply-To: <CA963C09-8477-44AA-90F4-14DB94E73B2F@zeit.io>
References: <CA963C09-8477-44AA-90F4-14DB94E73B2F@zeit.io>

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





view thread (42+ messages)  latest in thread

Message-ID: <a674bada-cfba-ee76-12ea-5d652f750e38@rodonnell.ie>
Permalink:  ../a674bada-cfba-ee76-12ea-5d652f750e38@rodonnell.ie/
Also on:    postgresql.org/message-id/a674bada-cfba-ee76-12ea-5d652f750e38@rodonnell.ie

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ray@rodonnell.ie, ar@zeit.io
  Subject: Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"
  In-Reply-To: <a674bada-cfba-ee76-12ea-5d652f750e38@rodonnell.ie>
  References: <CA963C09-8477-44AA-90F4-14DB94E73B2F@zeit.io> <a674bada-cfba-ee76-12ea-5d652f750e38@rodonnell.ie>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox