Re: duplicate key value violates unique constraint"chinese_price_infos_pkey" - Mailing list pgsql-general

From Ray O'Donnell
Subject Re: duplicate key value violates unique constraint"chinese_price_infos_pkey"
Date
Msg-id 8b4cf7fc-8c24-cb51-344f-03aea308d55f@rodonnell.ie
Whole thread Raw
In response to Re: duplicate key value violates unique constraint"chinese_price_infos_pkey"  (Arup Rakshit <ar@zeit.io>)
List 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@rodonnell.ie



pgsql-general by date:

Previous
From: Arup Rakshit
Date:
Subject: Re: duplicate key value violates unique constraint"chinese_price_infos_pkey"
Next
From: Michael Nolan
Date:
Subject: Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"