@brac.... until now I interpreted your question in a "performance-wise" way. If you referred to the "shortest" way and not care about performance, it's
ids = db().select(db.table.id).as_dict().keys() On Tuesday, February 19, 2013 11:02:23 PM UTC+1, Niphlod wrote: > > as_dict() iterates on the Rows object (it's a method on the fetched > resultset). It's not speedier by any measure than a loop. > > > > On Tuesday, February 19, 2013 10:55:07 PM UTC+1, Richard wrote: >> >> May be better use .as_ditc() but not sure the id get mapped into dict key >> you have to check, but if the key id is the row id you can iterate directly >> over dict like this : >> >> for id in dict: >> ... >> >> >> On Tue, Feb 19, 2013 at 4:51 PM, Richard Vézina <ml.richa...@gmail.com>wrote: >> >>> You can try this and see what you can do with that : >>> db(db.table).select(db.table.id).as_list() >>> >>> By selecting db.table.id you will prevent the overhead of web2py >>> compute=, represent=, etc. >>> >>> Richard >>> >>> >>> On Tue, Feb 19, 2013 at 4:26 PM, <brac...@gmail.com> wrote: >>> >>>> If I select all items in a database: >>>> >>>> rows = db(db.table).select() >>>> >>>> I can get the ids by doing something like: >>>> >>>> ids = [] >>>> for row in rows: >>>> ids.append(row.id) >>>> >>>> However, is there a better way to get the ids straight from the rows >>>> variable (without executing raw sql)? I feel like I'm iterating through >>>> the >>>> entire list of items twice by doing this. >>>> >>>> -- >>>> >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "web2py-users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to web2py+un...@googlegroups.com. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>> >>> >> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.