[erlang-questions] Mnesia and automatic generation of primary keys

Ulf Wiger ulf@REDACTED
Mon Jul 2 13:35:16 CEST 2007


I usually use

  {node(), erlang:now()}

when I need a persistently unique key.

It also functions as a timestamp, letting you
derive the creation time from the key.

BR,
Ulf W

2007/7/2, Matej Kosik <kosik@REDACTED>:
> Hello,
>
> The best tutorial to using Mnesia I have found is this document:
> http://www.erlang.org/documentation/doc-5.2/pdf/mnesia-4.1.pdf
>
> According to that information I was able to set up a database, add tables, entries and make some querries. Ok.
>
> Now when I am thinking about tables I need and their attributes, I would like to generate unique primary keys for new entries to certain tables (where none of their attributes is a clear candidate for primary key).
>
> Is there a lucid way to generate such primary keys (that will guarantee uniqueness of those keys during the whole lifetime of that table) regardless of how many times the system will be shut down and restarted. Do you also have this problem? How do you solve it?
>
> Should I set up some kind of global table where I can use "last used primary key (integer)" and gradually increment it as I will acquire new keys? Or can this information be somehow associated with particular tables (stored in a schema as an attribute of that table)?
>
> Regards
> --
> Matej Kosik
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>



More information about the erlang-questions mailing list