id_max = db.Node.id.max() maxID = db(db.Node).select(id_max).first()[id_max]
The key used to store the max value is actually the SQL expression generated by the .max() method, so the following should work as well: maxID = db(db.Node).select(db.Node.id.max()).first()['MAX(Node.id)'] The following explains what is going on: https://groups.google.com/forum/#!msg/web2py/WAw9Z97HJjU/b4XRX2w3xu8J. For more examples, see http://web2py.com/books/default/chapter/29/6#sum,-min,-max-and-len. Anthony On Monday, June 18, 2012 2:20:23 AM UTC-4, Annet wrote: > > In a function I need the id of the last record created in a previous > session. I tried: > > maxID=db(db.Node).select(db.Node.id.max()).first().id > > ... but that results in a key error on id. > > In a view, this {{=maxID}}, is being rendered as: > > <Row {'_extra': <Row {'MAX(Node.id)': 2035}>}> > > How do I get maxID=2035 > > > Kind regards, > > Annet >