mnesia key of last inserted record

Ryan Rawson <>
Mon Jun 26 00:12:58 CEST 2006


Since mnesia doesn't support 'auto increment' the last key is whatever
it was you chose!  Meaning that the first field in your tuple is the
key of the record, thus whatever it is you had it set to is what it
is.  If you want to support sequences, you need to do a seperate
sequence fetch in your own code, and thus know what the artifical key
would be.

Specifically you would have code like:

Record=#myRec{a=1,b=2,c=3} ,
mnesia:write(Record) ,
%%% what is the key? Well the key is '1' since a=1

-ryan

On 6/25/06, Roberto Saccon <> wrote:
> How can I get the key of the last inserted record at mensia ? Right
> after mnesia:write I need to know the key. I think  could construct
> something with mnesia:match_object() to retrieve that key, but there
> must must be something smarter and with less overhead to get that key
> !
>
> regards
> --
> Roberto Saccon
>



More information about the erlang-questions mailing list