Generating unique ids in Mnesia

Joel Reymont <>
Thu Aug 18 16:59:50 CEST 2005

Mainly, my question is that of how to ensure that each "generate new  
id" returns the next sequence number without a lot of error checking.

I could do the fold and get the max seqnum but another process could  
be doing the same at the same moment. One of them would surely  
overwrite the record when writing. I could retrieve the record and  
check if the stored process id the right one (I do store the pid in  
the record) but I wonder if there's a better way of doing this.

     Thanks, Joel

On Aug 18, 2005, at 4:48 PM, Joel Reymont wrote:

> Would I call mnesia:foldl() to figure out the maximum sequence  
> number and then create a new record with key seqnum + 1, all in the  
> same transaction?

More information about the erlang-questions mailing list