SQLite VDBE opcode

PureFunc

Invoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run) with arguments taken from register P2 and successors.

An example

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

INSERT INTO artists (name) VALUES ('Lower case')
addropcodep1p2p3p4p5
0Init02100
1OpenWrite02030
2OpenWrite170k(2,,)0
3OpenWrite260k(2,,)0
4SoftNull2000
5String8030Lower case0
6NewRowid0100
7HaltIfNull129923artists.name1
8Affinity230DBB0
9SCopy31200
10PureFunc0126lower(1)32
11IntCopy1700
12MakeRecord6250
13SCopy3900
14IntCopy11000
15MakeRecord9280
16MakeRecord23110
17IdxInsert156216
18IdxInsert289216
19Insert0111artists57
20Halt0000
21Transaction01101
22Null0400
23Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Affinity, Goto, Halt, HaltIfNull, IdxInsert, Init, Insert, IntCopy, MakeRecord, NewRowid, Null, OpenWrite, SCopy, SoftNull, String8, Transaction.

What the SQLite documentation says

Invoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run) with arguments taken from register P2 and successors. The number of arguments is in the sqlite3_context object that P4 points to. The result of the function is stored in register P3. Register P3 must not be one of the function inputs.

P1 is a 32-bit bitmask indicating whether or not each argument to the function was determined to be constant at compile time. If the first argument was constant then bit 0 of P1 is set. This is used to determine whether meta data associated with a user function argument using the sqlite3_set_auxdata() API may be safely retained until the next invocation of this opcode.

This opcode works exactly like Function. The only difference is in its name. This opcode is used in places where the function must be purely non-deterministic. Some built-in date/time functions can be either deterministic of non-deterministic, depending on their arguments. When those function are used in a non-deterministic way, they will check to see if they were called using PureFunc instead of Function, and if they were, they throw an error.

See also: AggStep, AggFinal, Function

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.

← Program · ReadCookie →