If you don't need a list, but just the last record, use the return value from insert:
last_id =db.table.insert(item="some item") On Mar 30, 2:00 am, TheDude <[email protected]> wrote: > Wouldn't last = db().select(db.table.ALL, orderby=~db.table.id, limit= > (1,))[0] be better? Since this way only one row is being retrieved and > less overhead? > > On Mar 29, 5:26 pm, mdipierro <[email protected]> wrote: > > > > > last = db().select(db.table.ALL).as_list()[-1] > > > On Mar 29, 3:42 pm, Michael <[email protected]> wrote: > > > > I wasn't sure if when you do > > > > query = db().select(db.table.ALL) > > > > returns as an array of items? > > > > I am trying to get the last item added into the TABLE. I thought i > > > could do: > > > > query = db().select(db.table.ALL) > > > last = query[-1] > > > return dict(last=last) > > > > but I am getting the following error: > > > > Traceback (most recent call last): > > > File "gluon/restricted.py", line 98, in restricted > > > File "/Users/michaelnovia/Documents/web2py/web2py.app/Contents/ > > > Resources/applications/philosaraptor/controllers/default.py", line 24, > > > in <module> > > > File "gluon/globals.py", line 75, in <lambda> > > > File "/Users/michaelnovia/Documents/web2py/web2py.app/Contents/ > > > Resources/applications/philosaraptor/controllers/default.py", line 9, > > > in quote > > > File "gluon/sql.py", line 2036, in __getitem__ > > > SyntaxError: SQLRows: no such row --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" 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 -~----------~----~----~----~------~----~------~--~---

