Re: unique problem - Mailing list pgsql-general

From Michael Fuhr
Subject Re: unique problem
Date
Msg-id 20041101155436.GA18546@winnie.fuhr.org
Whole thread Raw
In response to unique problem  ("Joolz" <joolz@arbodienst-limburg.nl>)
List pgsql-general
On Mon, Nov 01, 2004 at 04:13:43PM +0100, Joolz wrote:
>
> When importing a bunch of data (> 85000 rows) I get an error I can't
> explain. The table into which I'm importing has a unique clause on
> (code, bedrijf). The rows in the source-table are unique in this
> aspect, yet when I do the import I get this "ERROR: duplicate key
> violates unique constraint "werknemer_bedrijf_key".

How are you importing the data?  If you use COPY then the error
should show what line is causing the problem, and if you do individual
INSERTs then your import code should be able to recognize the error.
INSERT...SELECT probably won't identify the duplicate record.

> I checked the sourcetable a number of times, even COPYd the relevant
> columns to a textfile and did `uniq -d` and `uniq -D` (nothing
> non-unique found), tried to delete out non-unique rows (again
> nothing found).

Did you sort the file before you ran uniq?  Duplicate lines need
to be adjacent for uniq to recognize them.

% cat foo
abc
def
abc
% uniq -d foo
% sort foo | uniq -d
abc

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: spreading the DB?
Next
From: Tom Lane
Date:
Subject: Re: AT TIME ZONE: "convert"?