[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)

Which doesn't seem safe, as Ulf points on in that thread:

As well as slow.

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

-------------- 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