Kerry
Kerry

Reputation: 19

query mnesia data by where with 'or'

SQL: select account from y_account where id>5

Mnesia qlc:

F = fun() ->
    Q = qlc:q([E#y_account.account || E <- mnesia:table(y_account), E#y_account.id>5]),
    qlc:e(Q)
    end,
mnesia:transaction(F).

I can select data in mnesia like this. But how to select data by where containing 'or', like this SQL:

select account from y_account where id>5 or name='joe'

Thanks, Best regards

Upvotes: 0

Views: 103

Answers (2)

Danil Onishchenko
Danil Onishchenko

Reputation: 2040

Use operator or:

F = fun() ->
    Q = qlc:q([E#y_account.account ||
        E <- mnesia:table(y_account), (E#y_account.id > 5) or (E#y_account.name == "joe")]),
    qlc:e(Q)
    end,
mnesia:transaction(F).

Upvotes: 1

Pascal
Pascal

Reputation: 14042

I didn't check if there is a more efficient way, but you could replace

E#y_account.id>5 by (E#y_account.id>5) orelse (E#y_account.name == "joe")

Upvotes: 1

Related Questions