how to lookup last record in dataset in Mnesia?

Chandru chandrashekhar.mullaparthi@REDACTED
Wed Jun 7 15:34:59 CEST 2006


You can use mnesia:foldl/foldr probably. But this will traverse the entire
table everytime. Alternately, you could use an ordered_set table and then
use mnesia:dirty_last - but I don't think it meets your needs from what
you've said.

Chandru

On 07/06/06, Gaspar Chilingarov <nm@REDACTED> wrote:
>
> Hello all!
>
>
> I have a table in Mnesia, which I with to filter by some field(s) and
> fetch one record with maximal ID (ie. last inserted).
>
> The only method I can imagine -
>
> make qlc query, sort it by ID in reverse order, create qlc cursor and
> fetch exactly  1 record from resulting dataset.
>
> (SQL equivalent: SELECT MAX(ID) FROM table WHERE foo_field = 'bar' and
> user_name = 'Alice')
>
> Are there any fast ways to achieve this in mnesia?
>
> Thanks in advance, Gaspar
>
> --
> Gaspar Chilingarov
>
> System Administrator,
> Network security consulting
>
> t +37493 419763 (mob)
> i 63174784
> e nm@REDACTED
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060607/55a2f5a6/attachment.htm>


More information about the erlang-questions mailing list