Обсуждение: Primary Key problem

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

Primary Key problem

От
"ebp"
Дата:
It seems that any additions to our target table results in a violation:
 
[04/Mar/2002:14:08:43][2208.492550][-conn59-] Error: Ns_PgExec: result status: 7 message: ERROR:  Cannot insert a duplicate key into unique index kbeg_pkey
 
[04/Mar/2002:14:08:43][2208.492550][-conn59-] Error: dbinit: error(localhost::echonew,ERROR:  Cannot insert a duplicate key into unique index kbeg_pkey
): 'insert into kbeg values (nextval('kbeg_sequence'),'Anthony','Estevez','77th street','New York','NY','77777','7777777777','AnthonyEstevez@yahoo.com','notes',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Test',NULL,NULL,NULL)'
[04/Mar/2002:14:08:43][2208.492550][-conn59-] Error:
Database operation "dml" failed
    while executing
"ns_db dml $db "insert into kbeg values (nextval('kbeg_sequence'),[ns_dbquotevalue $fname],[ns_dbquotevalue $lname],[ns_dbquotevalue $address],[ns_dbqu..."
    invoked from within chunk: 0 of adp: /web/server1/www/kbegmailer/josestestsfiles/NewCharIn.adp
I was wondering how i could check/increment the key value, possibly to find out if there is data after the current key value. I believe that when we imported some files, they threw off the key values for some reason, probably jumping to some other starting point than the next available value.
 
-Anthony

Re: Primary Key problem

От
Oliver Elphick
Дата:
On Mon, 2002-03-04 at 19:13, ebp wrote:
> I was wondering how i could check/increment the key value, possibly to find out if there is data after the current
keyvalue. I believe that when we imported some files, they threw off the key values for some reason, probably jumping
tosome other starting point than the next available value. 

select setval('kbeg_sequence',(select max(your_sequence_field) from
kbeg));
--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "Give, and it will be given to you. A good measure,
      pressed down, taken together and running over,
      will be poured into your lap. For with the same
      measure that you use, it will be measured to
      you."         Luke 6:38