[erlang-questions] Mnesia with Records Confusion

Lee Sylvester lee.sylvester@REDACTED
Tue Apr 9 00:06:42 CEST 2013


Hey guys,

So, I have a record that looks a little like this

-record(user, {pid, username}).

That's a simplified version.  Anyhoo, I was trying to add it to and remove it from a table in Mnesia, but kept getting a badarg error.  I'd set the table up like so:

	mnesia:create_table(user,
		[
			{type,set},
			{record_name, user},
			{index, [pid]},
			{attributes, record_info(fields, user)}
		]),

This error had me baffled for a while as I was able to add records to the table, but couldn't read them with index_read.  I eventually found that the issue was to do with the index of the pid property in the record and, by adding an id property as the first field, all my problems disappeared.

Can someone please explain why this is so?  I mean, I'm glad it works now, but I'd love to know why I had to do this.

Thanks loads,
Lee




More information about the erlang-questions mailing list