Re: duplicate key errors when restoring 8.4.0 database dump into 9.1.2 - Mailing list pgsql-general

From Nigel Heron
Subject Re: duplicate key errors when restoring 8.4.0 database dump into 9.1.2
Date
Msg-id 4EFDE3E7.1050708@psycode.com
Whole thread Raw
In response to Re: duplicate key errors when restoring 8.4.0 database dump into 9.1.2  (Culley Harrelson <harrelson@gmail.com>)
Responses Re: duplicate key errors when restoring 8.4.0 database dump into 9.1.2
List 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.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: How to get the time zone offset
Next
From: "Cezariusz Marek"
Date:
Subject: Re: How to get the time zone offset