Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"

From: Michael Nolan <htfoot(at)gmail(dot)com>
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 15:13:33
Message-ID: CAOzAquJA6wjod8b70jw+2q-LZFm5DwVPUf5zuW_wstqFmj9KDA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 6, 2019 at 6:05 AM Arup Rakshit <ar(at)zeit(dot)io> wrote:

SELECT MAX(id) FROM chinese_price_infos; max -------- 128520(1 row)
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

Vacuuming the table doesn't change the fact that your sequence isn't
generating unique keys. Without knowing the full history of the table, I
can only speculate as to how keys got inserted that are beyond the
sequence's current vlue, but most likely you will need to use the sequence
manipulation function setval to set the sequence to at least one greater
than the current maximum value.
--
Mike Nolan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michel Pelletier 2019-05-06 15:49:42 Re: Looking for feedback and contributions
Previous Message Ray O'Donnell 2019-05-06 12:19:41 Re: duplicate key value violates unique constraint "chinese_price_infos_pkey"