How do I find the last record inserted?

Using [-1] requires the whole table to be scanned and it could be slow with large tables.

Ordering the query and getting the first item requires no scan and is faster, but you need one column with an incremental or a timestamp value, so you can do:

last_row = app_tables.my_table.search(tables.order_by('timestamp', ascending=False))[0]
7 Likes