Re: Problem with unique key - Mailing list pgsql-general

From Tomas Vondra
Subject Re: Problem with unique key
Date
Msg-id 456C0189.7080308@fuzzy.cz
Whole thread Raw
In response to Problem with unique key  ("Greg Peters" <gregpeters79@gmail.com>)
List pgsql-general
> ERROR:  duplicate key violates unique constraint "admin_field_list_pkey"
> CSG=#
>
> /I don't understand what is going on. It seems that it can't increment
> the primary key properly, or for some reason it's trying to assign an
> incorrect value to the key column. If i change the command to include a
> value for the key column (in this case the number 9), it seems to work.
> I've tried dumping/restoring the DB and also tried it on v8.1 and v8.2
> with no success. Any ideas?/
>
> Kind Regards,
>
> Greg Peters.

The problem is in the primary key constraint, not the unique one. I
guess you have inserted the previous rows with 'key' value specified
directly just like in:

=# insert into admin_field_list (key, field, added_by) values (1,
'Talinga', 'Greg Peters');

Thus the sequence is not set to the correct value and generates values
from 1 ... and these are already in the table. Try this

=# SELECT setval('admin_field_list_key_seq', (SELECT MAX(key) FROM
admin_field_list));

and then the insert again.

Tomas

pgsql-general by date:

Previous
From: "Greg Peters"
Date:
Subject: Problem with unique key
Next
From: Richard Huxton
Date:
Subject: Re: Problem with unique key