Re: duplicate key violates unique constraint - Mailing list pgsql-general

From Jeff Davis
Subject Re: duplicate key violates unique constraint
Date
Msg-id 1158625513.30652.24.camel@dogma.v10.wvs
Whole thread Raw
In response to duplicate key violates unique constraint  (vtaquette@globo.com)
Responses Re: duplicate key violates unique constraint  (Ron Johnson <ron.l.johnson@cox.net>)
List pgsql-general
On Mon, 2006-09-18 at 19:47 -0300, vtaquette@globo.com wrote:
> Hi,
>
> I'm trying to create a table with a PRIMARY KEY. The CREATE statement looks
> like this:
>
> CREATE TABLE  "projects" (
>   "project_id" serial,
>   "username" varchar(30) NOT NULL default '',
>   "project_name" varchar(30) NOT NULL default '',
>   PRIMARY KEY  ("project_id")
> ) ;
>
> The problem is that sometimes, I would say 1 in 10 tries, when I use a INSERT
> command I get the following error:
>
> "duplicate key violates unique constraint"
>
> The INSERT query is that:
> "INSERT INTO projects (\"project_name\", \"username\") VALUES ('$project_name',
> '$username')";
>

That INSERT statement will not cause a unique constraint violation. Are
you sure that is the statement causing the problem? Are there any rules
or triggers that may modify the behavior of that INSERT?

I suggest you turn on query logging, which you can do by setting the
configuration variable "log_statement" (found in postgresql.conf) to
'all'. Then you can see exactly what queries are being sent and which
one causes the error.

Regards,
    Jeff Davis



pgsql-general by date:

Previous
From: vtaquette@globo.com
Date:
Subject: duplicate key violates unique constraint
Next
From: Geoffrey
Date:
Subject: Re: server resetting