Re: duplicate key errors when restoring 8.4.0 database dump into 9.1.2

From: Nigel Heron <nigel(at)psycode(dot)com>
To: Culley Harrelson <harrelson(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: duplicate key errors when restoring 8.4.0 database dump into 9.1.2
Date: 2011-12-30 16:16:39
Message-ID: 4EFDE3E7.1050708@psycode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11-12-30 10:49 AM, Culley Harrelson wrote:
> They are just your standard sql errors seen in the output of psql mydb
> < backup.sql
>
>
> ALTER TABLE
> ERROR: could not create unique index "ht_user_pkey"
> DETAIL: Key (user_id)=(653009) is duplicated.
>
> There is a unique index on user_id in the 8..4.0 system and, of
> course, only one record for 653009.
>
>

Are you sure there is just one record? I had this same problem and it
was because there were a few rows that violated the primary key even
though the constraint existed since table creation. The db had a hard
crash once which might explain the bad data though.
run this to check your whole table for duplicates:

select user_id, count(*)
from ht_user
group by user_id
having count(*) > 1;

-nigel.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Cezariusz Marek 2011-12-30 16:19:51 Re: How to get the time zone offset
Previous Message Adrian Klaver 2011-12-30 16:13:52 Re: How to get the time zone offset