Nuwan Sameera
Nuwan Sameera

Reputation: 819

Select data rows with condition Erlang

I am new to erlang. I have following data record.

-record(tracked_connection, {id,node,vhost,name,pid,protocol,type,peer_host,peer_port,username,connected_at}).

I need to select data in following SQL format

Select * from tracked_connection where username = 'xxxxx';

All rows can get following code.

mnesia:select(Tab,[{'_',[],['$_']}]).

How I achieve my requirement.

Upvotes: 1

Views: 66

Answers (1)

legoscia
legoscia

Reputation: 41568

You can do it like this:

mnesia:select(Tab,[{#tracked_connection{username = "xxxxx", _ = '_'},[],['$_']}]).

That is, in the match spec, the username field of the record must match "xxxxx", while all other fields can be anything.

Upvotes: 2

Related Questions