SQLite VDBE opcode

TypeCheck

Apply affinities to the range of P2 registers beginning with P1.

An example

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

SELECT total FROM sales
addropcodep1p2p3p4p5
0Init01200
1OpenRead017040
2Rewind01100
3IfNullRow0910
4Column0220
5Column0330
6RealAffinity3000
7Multiply3210
8TypeCheck116sales0
9ResultRow1100
10Next0301
11Halt0000
12Transaction00101
13Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Goto, Halt, IfNullRow, Init, Multiply, Next, OpenRead, RealAffinity, ResultRow, Rewind, Transaction.

What the SQLite documentation says

Apply affinities to the range of P2 registers beginning with P1. Take the affinities from the Table object in P4. If any value cannot be coerced into the correct type, then raise an error.

If P3==0, then omit checking of VIRTUAL columns.

If P3==1, then omit checking of all generated column, both VIRTUAL and STORED.

If P3>=2, then only check column number P3-2 in the table (which will be a VIRTUAL column) against the value in reg[P1]. In this case, P2 will be 1.

This opcode is similar to Affinity except that this opcode forces the register type to the Table column type. This is used to implement "strict affinity".

GENERATED ALWAYS AS ... STATIC columns are only checked if P3 is zero. When P3 is non-zero, no type checking occurs for static generated columns. Virtual columns are computed at query time and so they are never checked.

Preconditions:

If any precondition is false, an assertion fault occurs.

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.

← Transaction · Vacuum →