Cast
Force the value in register P1 to be the type defined by P2.
An example
1 of the 178 statements we compiled against the sample database use Cast. This is the one with the shortest program; the rows that use Cast are highlighted.
SELECT CAST(ms AS TEXT), CAST('12' AS INTEGER) FROM tracks| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 10 | 0 | 0 | |
| 1 | OpenRead | 0 | 4 | 0 | 4 | 0 |
| 2 | Rewind | 0 | 9 | 0 | 0 | |
| 3 | Column | 0 | 3 | 1 | 0 | |
| 4 | Cast | 1 | 66 | 0 | 0 | |
| 5 | String8 | 0 | 2 | 0 | 12 | 0 |
| 6 | Cast | 2 | 68 | 0 | 0 | |
| 7 | ResultRow | 1 | 2 | 0 | 0 | |
| 8 | Next | 0 | 3 | 0 | 1 | |
| 9 | Halt | 0 | 0 | 0 | 0 | |
| 10 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 11 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Column, Goto, Halt, Init, Next, OpenRead, ResultRow, Rewind, String8, Transaction.
What the SQLite documentation says
Force the value in register P1 to be the type defined by P2.
- P2=='A' → BLOB
- P2=='B' → TEXT
- P2=='C' → NUMERIC
- P2=='D' → INTEGER
- P2=='E' → REAL
A NULL value is not changed by this routine. It remains NULL.
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.
← Blob · Checkpoint →