Search code examples
erlangets

ets match_object with match spec


 -record(rule, {id, low, high}).


 test_ets() ->
    ets:new(rule_table,[named_table,public,bag]),
    ets:insert(rule_table, #rule{id=1, low=2, high=5}),
    ets:match_object(rule_table, [{'$1',[{'>=', {element, #rule.low, '$1'}, 2}, 
            {'=<', {element, #rule.high, '$1'}, 5} 
            ], ['$_']}]).

This function only get an empty list while I want to pick this record with low =< X =< high.

Please help me. Thank you


Solution

  • I'm wrong, use ets:select instead.

    But how is the performance using matchSpec? Is it all table scan?