[erlang-questions] mnesia: composite keys?

Jacob Perkins japerk@REDACTED
Fri Jan 9 23:48:13 CET 2009


> I've read[1] that mnesia doesn't support composite keys. It seems I can use
> keys made up of tuples though:
>
> (emacs@REDACTED)11> mnesia:create_table(test, [{attributes, [id, data]}]).
> {atomic,ok}
> (emacs@REDACTED)19> Ins = fun() -> mnesia:write({test, {a_key, 0},
> "asdfasdf"})
> end.
> #Fun<erl_eval.20.67289768>
> (emacs@REDACTED)20> mnesia:transaction(Ins).
> {atomic,ok}
> (emacs@REDACTED)21> R = fun() -> mnesia:read(test, {a_key, 0}) end.
> #Fun<erl_eval.20.67289768>
> (emacs@REDACTED)22> mnesia:transaction(R).
> {atomic,[{test,{a_key,0},"asdfasdf"}]}
>
>
> Is tuples as keys common practice or A Really Bad Idea(tm)?
>

Tuple keys can actually be a Really Good Idea, especially with ordered_set
tables.

Jacob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090109/d3d088ba/attachment.htm>


More information about the erlang-questions mailing list