deleting records from mnesia

Serge Aleynikov serge@REDACTED
Wed Jul 19 18:17:04 CEST 2006


Hi,

Is there a way to delete all records from a table in mnesia within a 
transaction?

This won't work because mnesia:clean_table/1 doesn't support nested 
transactions:

F = fun() ->
         {atomic, ok} = mnesia:clear_table(Tab),
         insert_records(Tab)
     end,
mnesia:transaction(F).

I know that I could do this:

[mnesia:delete(Tab, Key, sticky_write) || Key <- mnesia:all_keys(Tab)].

but is there a way to truncate table in one shot within a transaction 
instead of iterating over all records?

Serge



More information about the erlang-questions mailing list