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

From Richard Huxton
Subject Re: Problem with unique key
Date
Msg-id 456C02A8.5020503@archonet.com
Whole thread Raw
In response to Problem with unique key  ("Greg Peters" <gregpeters79@gmail.com>)
Responses Re: Problem with unique key  ("Greg Peters" <gregpeters79@gmail.com>)
List pgsql-general
Greg Peters wrote:
> CSG=# \d admin_field_list
>                                      Table "public.admin_field_list"
>   Column    |            Type             |
> Modifiers
> -------------+-----------------------------+----------------------------------------------------------------
>
> key         | bigint                      | not null default
> nextval('admin_field_list_key_seq'::regclass)

> *Now, as you can see, there is no field called "Kogan North", but when I
> enter the command:*

> CSG=# insert into admin_field_list (field, added_by) values ('Kogan North',
> 'Greg Peters');

> ERROR:  duplicate key violates unique constraint "admin_field_list_pkey"

It's not complaining about "field" but about "key" - look at the
constraint name. I'm guessing you've added rows with manual values for
the "key" column. The sequence doesn't know about these, so is
generating values already in use.

You can use setval(<sequence-name>) to update the sequence's value.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: Problem with unique key
Next
From: "Greg Peters"
Date:
Subject: Re: Problem with unique key