SQLite VDBE opcode

Last

The next use of the Rowid or Column or Prev instruction for P1 will refer to the last entry in the database table or index.

Jumps: P2 is an instruction address. In the listings here, a jump is drawn as an arc and the address is a link.

An example

6 of the 178 statements we compiled against the sample database use Last. This is the one with the shortest program; the rows that use Last are highlighted.

SELECT name FROM artists ORDER BY name DESC LIMIT 3
addropcodep1p2p3p4p5
0Init01000
1Noop1300
2Integer3100
3OpenRead260k(2,,)0
4Last29200
5Column2020
6ResultRow2100
7DecrJumpZero1900
8Prev2501
9Halt0000
10Transaction00101
11Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, DecrJumpZero, Goto, Halt, Init, Integer, Noop, OpenRead, Prev, ResultRow, Transaction.

What the SQLite documentation says

The next use of the Rowid or Column or Prev instruction for P1 will refer to the last entry in the database table or index. If the table or index is empty and P2>0, then jump immediately to P2. If P2 is 0 or if the table or index is not empty, fall through to the following instruction.

This opcode leaves the cursor configured to move in reverse order, from the end toward the beginning. In other words, the cursor is configured to use Prev, not Next.

From sqlite.org's list of opcodes for SQLite 3.54.1, in the public domain. Opcodes are not a stable interface and change between releases.

← Jump · Le →