SQLite Forum

User-defined functions in the CLI?
Login
Maybe that one?
<https://github.com/0x09/sqlite-statement-vtab/>

Mentioned [here](https://sqlite.org/forum/forumpost/28c03d56a16d3301?t=h) and [here](https://sqlite.org/forum/forumpost/29c15b0d406ef65e?t=h).

Can be (ab)used as 'function' by wrapping the table-valued-function as scalar subquery ...

~~~
sqlite> .load ./statement_vtab

sqlite> CREATE VIRTUAL TABLE twice USING statement((SELECT 2 * :x as y));
sqlite> select (select y from twice(9)) as result;
result
18
~~~

or - arguably less clumsy - with a join

~~~
sqlite> create table t1(v);
sqlite> insert into t1 values(4),(7),(99);

sqlite> select t1.v, twice.y as r from t1 left join twice(t1.v);
v|r
4|8
7|14
99|198
~~~