On GAE, the default ordering depends on which index is needed to answer the query, and it is stable, so it is non-random.
To get random rows on GAE, I use a float field called random, which is assigned a float from 0 and 1, then to pull random rows, I just generate a random float and query by table.random < value. Robin On Sep 9, 10:12 pm, mdipierro <[email protected]> wrote: > No but I believe that without orderby it may be random by default on > GAE. I would check the GAE docs because I am not sure. > > On Sep 9, 10:01 pm, Iceberg <[email protected]> wrote: > > > Thanks! Did not notice the '<random>' is supported by web2py DAL for > > its all db backend. That is great. Does it work on GAE too? > > > BTW, my less efficient way is db-independent however. > > > On Sep10, 9:55am, mdipierro <[email protected]> wrote: > > > > I thought I answered this > > > > random_record = db().select(db.mytable.ALL,orderby='<random>,limitby= > > > (0,1))[0] > > > > On Sep 9, 8:27 pm, Iceberg <[email protected]> wrote: > > > > > On Sep9, 8:07pm, Richard <[email protected]> wrote: > > > > > > hi, > > > > > > is there an efficient way to get a random record from a table? > > > > > An obvious non-efficient way would be to get all the records and do > > > > > random.choice(). > > > > > > thanks, > > > > > Richard > > > > > Would like to see comments on this. > > > > > import random > > > > total_count = db(db.mytable.id>1).count() # well, this is one extra > > > > db query > > > > random_id = random.randint(1, total_count) > > > > random_record = db.mytable[random_id] # Does this work on GAE? > > > > > Iceberg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

