[erlang-questions] Can one have more than one secondary index on a mnesia table?

Dan Gudmundsson dgud@REDACTED
Mon Oct 23 10:35:58 CEST 2017


Remove the tuple in the second call:

mnesia:index_read(?TABLE, MemberID, 3)
vs
mnesia:index_read({?TABLE, Penname, 5})

/Dan

On Sun, Oct 22, 2017 at 9:15 PM <lloyd@REDACTED> wrote:

> Hello,
>
> Initialized table:
>
> init_table() ->
>     mnesia:create_table(?TABLE,
>         [ {disc_copies, [node()] },
>           {attributes, record_info(fields, ?TABLE)},
>           {index, [member_id, penname]}
>         ]).
>
> Checked info:
>
> $ wg_schema(wg_table).
> ....
> {index,3}            -> 376866
> {index,5}            -> 380964
>
> This query works:
>
> get_author_by_member_id(MemberID) ->
>     Query =
>         fun() ->
>             mnesia:index_read(?TABLE, MemberID, 3)
>         end,
>     {atomic, Result} = mnesia:transaction(Query),
>     Result.
>
> But this doesn't:
>
> get_author_by_penname(Penname) ->
>     Query =
>         fun() ->
>             mnesia:index_read({?TABLE, Penname, 5})
>         end,
>     {atomic, Result} = mnesia:transaction(Query),
>     {length(Result), Result}.
>
> Am I doing something wrong? Or is there something I should be doing
> altogether?
>
> Thanks to all,
>
> LRP
>
>
>
>
> *********************************************
> My books:
>
> THE GOSPEL OF ASHES
> http://thegospelofashes.com
>
> Strength is not enough. Do they have the courage
> and the cunning? Can they survive long enough to
> save the lives of millions?
>
> FREEIN' PANCHO
> http://freeinpancho.com
>
> A community of misfits help a troubled boy find his way
>
> AYA TAKEO
> http://ayatakeo.com
>
> Star-crossed love, war and power in an alternative
> universe
>
> Available through Amazon or by request from your
> favorite bookstore
>
>
> **********************************************
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171023/41520301/attachment.htm>


More information about the erlang-questions mailing list