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 -~----------~----~----~----~------~----~------~--~---

