Inserting without overwriting with mnesia or ets
Einar Karttunen
ekarttun@REDACTED
Fri May 7 14:29:13 CEST 2004
Hello
I need a way to insert into ets/mnesia and fail if the
key already exists. These failures should be very rare
and exceptional, but not checking for them could corrupt
data... Is there an efficient solution to this?
The naive approach is not very good:
insert(K,V) ->
fun() ->
case mnesia:wread(K) of
[Exist] -> {abort, Exist};
_ -> mnesia:write(V)
end
end.
- Einar Karttunen
More information about the erlang-questions
mailing list