I’m using MySQLdb library to connect to MySQL within my Python script.
(Ref: http://mysql-python.sourceforge.net/MySQLdb.html ).
I would like to learn if there is a way to jump to the last record in a resultset using Python?
In other words, I would like to move my cursor to the last record in the resultset.
Well, your question is weird. Why would you want to do that?
You could keep reading records from the cursor until it is the last. But you’d have to try reading past it to know it is the last one, you can’t know before reading it.
Another idea is to make a reversed query. Use
ORDER BYto reverse the result order and the last will come first.Or if you know the number of records, you could use
OFFSETto return only the last one. You could issue aCOUNTquery first to know the number, and then use this number onOFFSET.