[erlang-questions] clarify: qlc, mnesia and unique_all

Dmitri Girenko <>
Sun Jan 20 12:19:55 CET 2008

Hi all,
I am having strange problems with qlc's unique_all option.
Here is the test code:

 [mnesia:dirty_write({t, I, I div 2}) || I <- lists:seq(1,10)],
 Q1=qlc:q([element(3,T) || T <- mnesia:table(t)]),
 exec(fun() -> qlc:e(Q1) end),     
 exec(fun() -> qlc:e(Q1, unique_all) end),
 exec(fun() -> qlc:e(qlc:sort(Q1), unique_all) end),
 exec(fun() -> qlc:e(qlc:sort(qlc:e(Q1)), unique_all) end).
 {atomic, R} = mnesia:transaction(F),
 io:format("~p~n", [ R ]).

And here is the outpit:
So it looks like if the argument to qlc:sort is a mnesia query handle, then all the elements are returned. If it's a list, then only unique value are returned. Does the {unique, true} flag concern only records, but no the result values?
runtime version is R11B-5

Best regards,

More information about the erlang-questions mailing list