I have the following small table in Erlang mnesia database. When I use the dirty_select function as follows:
mnesia:dirty_select(user, [{#user{id = '$1', name = martin}, [], ['$1']}]).
I get the error:
* 1: record user undefined
The user table has one row with user id as primary key and ‘martin’ as the name of the user.
When I use the following command, it works well:
mnesia:dirty_read(user, 1).
And the output is:
[{user,1,martin}]
What could be the reason for the above error?
if you are getting this error when using the erlang shell, you will need to define the record. records are a compile time construct and the shell does not have access to their definitions.
once you have defined the record, your dirty_read operation will print the result using record syntax.