ERROR: duplicate key violates unique constraint

From: "remco lengers" <pgsql(at)lengers(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: ERROR: duplicate key violates unique constraint
Date: 2007-03-20 09:11:41
Message-ID: 32207abd0703200211l46acdab7p5a2d68d69ffc5b6c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi List,

Its been a while since I worked with databases and I am running into the
following which I have not been able to find the root cause for:

I have the follow SQL statement:

INSERT INTO reference VALUES (DEFAULT,'123','2',1);

Which generates the following error:

"ERROR: duplicate key violates unique constraint "reference_pkey""

And the table definition looks like:

CREATE TABLE reference (
referencelist_nr serial unique,
reference_text varchar(40) NOT NULL,
reference_type integer NOT NULL,
Topic_Id integer NOT NULL,
PRIMARY KEY (referencelist_nr),
FOREIGN KEY (Topic_Id) REFERENCES Topic (Topic_Id),
FOREIGN KEY (reference_type) REFERENCES reference_type (reference_type_nr)
);

It seems to me for some reason "DEFAULT" doesn't select the next SERIAL.
If I run:

INSERT INTO reference VALUES (14,'123','2',1);

14 being the next free integer it works fine.....

I have been adding data with "COPY" into this table....does that break
something?

Your help/tips/insights are appreciated.

Solaris 10/Postgresql 8.1.4

Regards,

..Remco

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stefan Ionita 2007-03-20 09:17:43 unsubscribe
Previous Message Michael Fuhr 2007-03-20 03:41:11 Re: How to declare cursor if tablename is a variable?