Bug 225221 - a primary key for longdescs

Joel Peshkin bugreport at peshkin.net
Thu Oct 14 21:13:36 UTC 2004

Christopher Hicks wrote:

> That won't work!  How can you assign integers to something you can't 
> uniquely refer to?  The simplest and most painless way to get past the 
> chicken and egg problem is by having MySQL do it (as my patches have 
> done) you end up with a primary key already filled out for you.  It 
> seems so simple yet its taken so long and folks still don't get it.  
> So I gripe.

You go through the existing rows in checksetup and identify them and 
assign them integers.  if you really find 2 identical rows, the LIMIT 1 
in the update statement will take care of it.

Pseudocode for checksetup....

alter table longdescs add column newkey int;
select bug_id, bug_when, bug_who from longdescs order by bug_id, bug_when;
while (row)
      update longdescs set newkey = $nextnumber where bug_id = $id AND 
bug_when = $when AND bug_who = $who LIMIT 1
    until no_rows_updated

alter table longdescs alter column newkey auto_increment primary key

More information about the developers mailing list