Mnesia and uniqueness on two keys

Ulf Wiger <>
Wed Jul 13 15:36:54 CEST 2005


Den 2005-07-13 10:52:25 skrev Joel Reymont <>:

> How is uniqueness ensured then?
>
> Based on?
>
> On Jul 13, 2005, at 8:25 AM, Samuel Rivas wrote:
>
>>   The key is the first element of the record. The OID is the tuple with
>> the record name and the key.

For indexes, uniqueness is not checked at all.

Ets and dets tables (the underpinnings of mnesia) enforce uniqueness
if you use the 'set' or 'ordered_set' semantics. An existing
object with the same key is simply replaced.

In ets, you can use the rather new function ets:insert_new/2,
which will insert the object, or list of objects, only if
there isn't already a conflicting key in the table; otherwise
it returns 'false'. With mnesia, you have to check for yourself,
if you don't want to overwrite objects.

/Uffe






More information about the erlang-questions mailing list