[erlang-questions] Mnesia: Error on insert object with same key in Set

Tristan Sloughter tristan.sloughter@REDACTED
Sun Oct 16 23:29:01 CEST 2011


I wanted to make sure there was still no way to tell Mnesia to return an
error if it is given a record to write that has the same key as an object
already stored in the table.

Reading through the docs it looks like there is no way through configuration
but you must simply read and then write if its not there, like I found when
this was asked in 2004 on this mailing list:

insert(K,V) ->
  fun() ->
  case mnesia:wread(K) of
    [Exist] -> {abort, Exist};
    _ -> mnesia:write(V)
  end
  end.

Which doesn't seem safe, as Ulf points on in that thread:
http://erlang.org/pipermail/erlang-questions/2004-May/012307.html

As well as slow.

So I was hoping maybe in 2011 there is a better way to do this? :)

Thanks,
Tristan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111016/8ef57297/attachment.htm>


More information about the erlang-questions mailing list