Reputation: 4476
I have a table with the following attributes:
SortCode Index Created
SortCode
is the primary key and Index
is secondary key. Given an Index
value, how do I get the associated SortCode
value?
I have tried ets:lookup/3
but it takes only a primary key.
Upvotes: 2
Views: 1836
Reputation: 26131
There is not such thing as a secondary index in ets
. You can do:
ets:match
or ets:select
orets
table ormnesia
with added (secondary) index.Upvotes: 3
Reputation: 4476
Adding to what Hynek -Pichi- Vychodil has said.
There is no solution in ets to fetch record using some other attribute apart from the key. It can be done using mnesia:dirty_index_read()
.
If you want to use ets only then you can do as above suggestion or follwoing code. Assuming your record pattern is omething like : {"one",1,"27092015"}
Key is "one" but you have to fetch using 1.
FilterSuspCodeFun = fun ({_,I,_}) when I == 1 -> true ; (_) -> false end,
ListData = ets:tab2list(susp_code),
{SortCode,_,created}= lists:filter(FilterSuspCodeFun,ListData),
Upvotes: -2