Re: best practice for inserting next token ?
Posted in 2010
Hi. First, I'm not sure you can't change the datatype... The code to insert doesn't exist. If your current datatype is an integer, they would'n probably need to change any code... But any way: - You can use sequences - You could BEGIN WORK; INSERT maximum possible value, get the correct value; UPDATE the value. Other sessions should be lock mode wait... and should be waiting on this transaction. Needs testing/checking - You could have a table with just one record.... and do a BEGIN WORK;UPDATE table SET val=val+1; SELECT val FROM table;COMMIT This is a workaround for not having sequences. Regards. On Mon, Jun 14, 2010 at 3:05 PM, Floyd Wellershaus <floyd@fwellers.com>wrote: > Hi, > We have a table whose primary key ( an integer ) acts like a serial token, > but is not a serial datatype. > We have a need to have a piece of code that would randomly insert new rows. > As far as I know, the only way is to select max(token) and then use the > next highest integer in the insert statement. > The problem is we need to make sure that nothing sneeks in and grabs that > token, between the select max and the insert. > The only think i can think of is to lock the table for update before doing > the select in a transaction. > Is there something I'm missing or is there another practice that is used in > these scenarios ? > > No, I can't change the datatype to what it should be, because that means > our developers would have to modify code and they don't do that. < satire > > > Thanks !! > Floyd > > > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list > > -- Fernando Nunes Portugal http://informix-technology.blogspot.com My email works... but I don't check it frequently...