Mnesia and uniqueness on two keys
ke.han
ke.han@REDACTED
Wed Jul 13 13:20:48 CEST 2005
Joel Reymont wrote:
> I have a record defined like this:
>
> -record(tick_data, {
> symbol,
> date,
> ticks % tuple
> }).
>
> I create the table like this:
>
> mnesia:create_table(tick_data,
> [
> {disc_copies, Nodes},
> {index, [date]},
> {type, set},
> {attributes, record_info(fields, tick_data)}
> ])
>
> My intent is to have a table where multiple records with the same
> symbol but different dates can coexist. Will the above work or do I
> need to create a bag table?
>
> In other words, does Mnesia expect uniqueness on each keys or do both
> keys work as a composite?
>
> Thanks, Joel
Joel,
I'm a novice, but my understanding is that the first field to your
record is always the key. So if you want to key by symbol and date, you
have the first field as a tuple {symbol, date} and the second field is
ticks. This means you get the keying and querying as you desire. You
simply have to unpack the tuple in order to get at the symbol or date
values.
I would appreciate if someone more experienced can confirm/deny my
understanding.
thanks, ke han
>
> --
> http://wagerlabs.com/uptick
>
>
>
>
More information about the erlang-questions
mailing list