[erlang-questions] Mnesia wildcard query

karol skocik karol.skocik@REDACTED
Tue May 14 12:32:09 CEST 2013


You can use ets:fun2ms/1 to construct example match spec, which can be also
used for select over mnesia table:

3> Tab = ets:new(tab, []).
20496
4> ets:insert(Tab, [{"abcdef", 1}, {"abxxxxx", 2}, {"bbbbbb", 3}]).
true
5> MatchSpec = ets:fun2ms(fun ({[$a, $b | _], V}) -> V end).
[{{[97,98|'_'],'$1'},[],['$1']}]
6> ets:select(Tab, MatchSpec).
[1,2]

ets:fun2ms/1 does not recognize literal funs like: fun ({"prefix" ++ _, V)
-> V end, (++ is the problem)
so it's more convenient to write a simple wrapper function returning the
MatchSpec, given the prefix.

Cheers,
  Karol


On Tue, May 14, 2013 at 10:44 AM, Janos Hary <janos.n.hary@REDACTED> wrote:

> Hi,****
>
> ** **
>
> Is there a way to specify a ‘begins with’ style query in Mnesia? My keys
> are strings, and I’d like to get all of them sharing a given prefix.****
>
> ** **
>
> Thanks,****
>
> Janos****
>
> _______________________________________________
> 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/20130514/6e72d441/attachment.htm>


More information about the erlang-questions mailing list