Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"

From: Ray O'Donnell <ray(at)rodonnell(dot)ie>
To: Arup Rakshit <ar(at)zeit(dot)io>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"
Date: 2019-05-06 12:19:41
Message-ID: 8b4cf7fc-8c24-cb51-344f-03aea308d55f@rodonnell.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 06/05/2019 12:10, Arup Rakshit wrote:
> Hi,
>
> Thanks for your reply. It is automatic, my app don’t creates ID, it
> delegates it to the DB. I am using Ruby on Rails app, where we use
> Postgresql.

Well, I'm only throwing out wild guesses, but another possibility is
that rows were loaded manually into that table which had different
values for the id column; this would lead to what you see.

Anyway, I'd fix the sequence value first with setval(), and then observe
for a while; if you're still getting id collisions, then something is
definitely inserting id values independently of the sequence. Remember,
the sequence is only used as a default for that column; if you insert a
value into the column, the sequence isn't used and so its current value
doesn't change.

Ray.

--
Raymond O'Donnell // Galway // Ireland
ray(at)rodonnell(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Nolan 2019-05-06 15:13:33 Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"
Previous Message Arup Rakshit 2019-05-06 11:10:50 Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"