The SQLite pragma_function_list() table-valued function returns a list of functions that have been registered with SQLite, including functions that were added by extensions.
Here’s how to interpret its output.
First, an example:
1
select*from pragma_function_list() order by random()
I’m using order by random() here just to mix things up a bit. Here are the first five results:
name
builtin
type
enc
narg
flags
likely
1
s
utf8
1
2099200
json_extract
1
s
utf8
-1
2048
ceiling
1
s
utf8
1
2099200
ulid_bytes
0
s
utf8
1
0
row_number
1
w
utf8
0
2097152
name is the name of the function
builtin shows if the function is built-in to SQLite or was added by an extension
type tells you what kind of function it is - the options are s for scalar, w for window and a for aggregate.
enc I’m not sure about. It’s always utf8 from what I’ve seen.
narg is the arity of the function: the number of arguments it takes. -1 means an unlimited number of arguments.
flags is more complicated, see below
In this example ulid_bytes is a function added because I loaded the sqlite-ulid extension.
I hadn’t realized that json_extract() could take unlimited arguments - I thought it just took a value and a path. From the above I learned that this works:
1
select json_extract('{"foo": "bar", "bar": "baz"}', '$.foo', '$.bar') as bits
This returns a JSON array corresponding to each argument past the first one:
Here’s the official SQLite documentation for those function flags.
deterministic means that the function is guaranteed to return the same result for the same input, which is a useful hint that the SQL query executor can reuse those values without re-calculating them every time.
directonly means that the function can only be called from “top-level SQL”, not from triggers, views or things like generated columns or check constraints.
innocuous means that the function is “unlikely to cause problems even if misused” - crucially, it means the function has no side effects.
subtype looks like it’s a window function concern - though I haven’t yet found an example of a function that uses it. The documentation says “Specifying this flag makes no difference for scalar or aggregate user functions. However, if it is not specified for a user-defined window function, then any sub-types belonging to arguments passed to the window function may be discarded before the window function is called (i.e. sqlite3_value_subtype() will always return 0).” I don’t understand the implications of this at all.