[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:
 
-module(test).
-export([test/0]).

-include_lib("stdlib/include/qlc.hrl").
 
test()->
 mnesia:start(),
 mnesia:create_table(t,[]),
 [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).
 
exec(F)->
 {atomic, R} = mnesia:transaction(F),
 io:format("~p~n", [ R ]).

 
And here is the outpit:
[0,5,1,1,4,2,2,3,3,4]
[0,5,1,1,4,2,2,3,3,4]
[0,1,1,2,2,3,3,4,4,5]
[0,1,2,3,4,5]
 
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,
Dmitri



More information about the erlang-questions mailing list