Re: duplicate key violates unique constraint

Поиск
Список
Период
Сортировка
От brian
Тема Re: duplicate key violates unique constraint
Дата
Msg-id 450F53B4.6070305@zijn-digital.com
обсуждение исходный текст
Ответ на Re: duplicate key violates unique constraint  (Ron Johnson <ron.l.johnson@cox.net>)
Ответы Re: duplicate key violates unique constraint  (Ron Johnson <ron.l.johnson@cox.net>)
Список pgsql-general
Ron Johnson wrote:
> On 09/18/06 19:25, Jeff Davis wrote:
>
>>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?
>
>
> If there already are records in the table, sure it would.
>
> ...
>
> dupe_filenames=# insert into projects (project_id, username )
> dupe_filenames-# values (1, 'foo');
> INSERT 0 1
> dupe_filenames=# insert into projects (project_id, username )
> dupe_filenames-# values (2, 'bar');
> INSERT 0 1
 >
> ...
>
> dupe_filenames=# insert into projects (project_id, username )
> dupe_filenames-# values (1, 'foo');
> ERROR:  duplicate key violates unique constraint "projects_pkey"
>
>

If you insert a project_id, yes. The original query from vtaquette does not.

brian

В списке pgsql-general по дате отправления:

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: duplicate key violates unique constraint
Следующее
От: Ron Johnson
Дата:
Сообщение: Re: duplicate key violates unique constraint