Inserting without overwriting with mnesia or ets

Einar Karttunen <>
Fri May 7 14:29:13 CEST 2004


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)

- Einar Karttunen

More information about the erlang-questions mailing list