Обсуждение: Cannot insert a duplicate key into unique index

Поиск
Список
Период
Сортировка

Cannot insert a duplicate key into unique index

От
Adelaide Yip
Дата:
Hi,


I get the following error when I try to insert into the table fees, even
when the primary and unique key are serial:

Warning: PostgreSQL query failed: ERROR: Cannot insert a duplicate key
into unique index fee_uk


INSERT INTO fees (registrar_name) VALUES ('blah');


Table 'fees'

     Attribute      |     Type      |                   Modifier

--------------------+---------------+-----------------------------------------------
 fee_id             | numeric(12,0) | not null default
nextval('general_seq'::text)
 registrar_name     | varchar(30)   | not null

Indices: fee_pk,
         fee_uk


I don't understand why I get this error when the fee_id column is serial
by default.  How can I fix this error?  And, how can I display what
value "nextval('general_seq'::text)" returns?

Thanks in advance,
Adelaide





Re: Cannot insert a duplicate key into unique index

От
"V i s h a l Kashyap @ [Sai Hertz And Control Systems]"
Дата:
Dear Adelaide  ,

>Warning: PostgreSQL query failed: ERROR: Cannot insert a duplicate key
>into unique index fee_uk
>
>
Check the max value in data base for the same index key and then check if
the max value agree with the sequence .
do some thing like
<code>
select max(fees.fee_id);
then
select nextval('general_seq'::text);
</code>
on psql command prompt
Now if the max value of  fees.fee_id
is greater than what  nextval returns
then this sequence has to be fixed

Have you recently done an dump restore ?

--
Best Regards,
Vishal Kashyap
Director / Lead Developer,
Sai Hertz And Control Systems Pvt Ltd,
http://saihertz.rediffblogs.com
Jabber IM: vishalkashyap@jabber.org
ICQ :      264360076
-----------------------------------------------
You yourself, as much as anybody in the entire
universe, deserve your love and affection.
- Buddha
---------------
I am usually called by the name Vishal Kashyap
and my Girlfriend calls me Vishal CASH UP.
This is because everyone loves me as Vishal Kashyap
and my Girlfriend loves me as CASH.
                    ___
                   //\\\
                  ( 0_0 )
----------------o0o-----o0o---------------------