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

lloyd@REDACTED lloyd@REDACTED
Sun Oct 22 21:15:22 CEST 2017


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


**********************************************




More information about the erlang-questions mailing list