pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bart Degryse <Bart.Degryse@indicator.be>
To: remco lengers <pgsql@lengers.com>
To: pgsql-sql@postgresql.org
Subject: Re: ERROR: duplicate key violates unique constraint
Date: Tue, 20 Mar 2007 10:20:32 +0100
Message-ID: <45FFB56F.A3DD.0030.0@indicator.be> (raw)
In-Reply-To: <32207abd0703200211l46acdab7p5a2d68d69ffc5b6c@mail.gmail.com>
References: <32207abd0703200211l46acdab7p5a2d68d69ffc5b6c@mail.gmail.com>

Use
INSERT INTO reference(reference_text, reference_type, Topic_Id) VALUES (DEFAULT,'123','2',1); 
instead.
Since referencelist_nr is a serial PostgreSQL will provide the next free integer itself.


>>> "remco lengers" <pgsql@lengers.com> 2007-03-20 10:11 >>>
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 

view thread (6+ messages)  latest in thread

Message-ID: <45FFB56F.A3DD.0030.0@indicator.be>
Permalink:  ../45FFB56F.A3DD.0030.0@indicator.be/
Also on:    postgresql.org/message-id/45FFB56F.A3DD.0030.0@indicator.be

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: Bart.Degryse@indicator.be, pgsql@lengers.com
  Subject: Re: ERROR: duplicate key violates unique constraint
  In-Reply-To: <45FFB56F.A3DD.0030.0@indicator.be>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox