Re: Problem with unique key

From: Richard Huxton <dev(at)archonet(dot)com>
To: Greg Peters <gregpeters79(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with unique key
Date: 2006-11-28 09:34:32
Message-ID: 456C02A8.5020503@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Peters 2006-11-28 09:35:15 Re: Problem with unique key
Previous Message Tomas Vondra 2006-11-28 09:29:45 Re: Problem with unique key