Why am I getting the error: "Cannot insert a duplicate key into unique index"?

Why am I getting the error: "Cannot insert a duplicate key into unique index"?

Post by Daniel Secom » Thu, 09 Sep 2004 22:48:05



Hi,

I'm using PostgreSQL 7.3.4 on phpPgAdmin 2.4.2 and I'm getting the following
error when I try and run a SQL query on a script:

Error -
/usr/local/psa/admin/htdocs/domains/databases/phpPgAdmin/db_readdump.php --
Line: 33
PostgreSQL said: ERROR: Cannot insert a duplicate key into unique index
inventory_pkey
Your query:
INSERT INTO "inventory"
("code","quantity","id","description","price","category","image","file","dat
e","uid","sub_type1","sub_type2","sub_type3","title","gst","gauge") VALUES
('1123',NULL,17,'Not really sure what to put in here But I am sure i will
told
:)','17.30',1,NULL,NULL,'2001-01-17',1,'Beans\015\012Means\015\012Hines','',
'','African Mist','0.00',7);

Any idea as to why this is doing this?

Thank you for your help.

Dan

 
 
 

Why am I getting the error: "Cannot insert a duplicate key into unique index"?

Post by p.. » Thu, 09 Sep 2004 23:16:46


You are trying to insert a value into a column that is declared as unique,
this value must already be in the column so pg rejects it.

Quote:

> Hi,

> I'm using PostgreSQL 7.3.4 on phpPgAdmin 2.4.2 and I'm getting the following error when
> I try and run a SQL query on a script:

> Error - /usr/local/psa/admin/htdocs/domains/databases/phpPgAdmin/db_readdump.php --
> Line: 33
> PostgreSQL said: ERROR: Cannot insert a duplicate key into unique index
> inventory_pkey
> Your query:
> INSERT INTO "inventory"
> ("code","quantity","id","description","price","category","image","file","date","uid","sub_t
> ype1","sub_type2","sub_type3","title","gst","gauge") VALUES ('1123',NULL,17,'Not really
> sure what to put in here But I am sure i will told :)','17.30',1,NULL,NULL,'2001-01-
> 17',1,'Beans\015\012Means\015\012Hines','','','African Mist','0.00',7);
> Any idea as to why this is doing this?
> Thank you for your help.
> Dan


 
 
 

1. ERROR: Cannot insert a duplicate key into a unique index

[SQL] ERROR:  Cannot insert a duplicate key into a unique index

I'm working on a C code application using loads of
insert commands.
It is essential to distinguish between an error
coming from a misformed command or other fatal
reasons and a duplicate key.
In either case, the PQresultStatus() returns
PGRES_FATAL_ERROR
I can check PQresultErrorMessage() for the
error message above, but then I have to rely
on this string never be changed.
This is no good programming style.
Does anybody have another, better idea or is
there at least a header file available, where
all the error messages can be found?

Regards, Christoph

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

2. applets

3. Cannot insert a duplicate key into unique index

4. Another Programmer's Editor(tm) 2.0R1 now available

5. Looking for Spy vs. Spy

6. Why am I getting a "kids passport" message?

7. HPUX9.1 m68k vsnprintf

8. Why am I getting this warning "dataset may be incomplete" ?

9. ERROR: UNIQUE constraint matching given keys for referenced table "sequences" not found

10. !)fmt gets error "mesg: cannot stat"

11. Why oh Why "Cannot put inside global/macro"

12. !!!!!"""""IMPORTANTE"""""!!!!!