A sqlite3 extension to generate sql functions in code
SELECT create_function(function_name, arg_count, flags, body);where function_name, flags and body are TEXT and arg_count is INTEGER
SELECT create_function_v2(function_name, flags, body, ...args);where function_name, flags and body are TEXT and ...args is a comma separated list of TEXT representing the argument names in order
For exemple,
SELECT create_function_v2('add', 'di', 'a+b+c', 'a', 'b', 'c');A reducer function is a function that takes a list of values (as varargs) or rows (from a SELECT statement) and process them into a single value.
SELECT create_reducer(name, flags, body[, accname, currname]);Usage
SELECT create_reducer('sum', 'di', 'acc+curr');
SELECT sum(1, 2, 3, 4); -- 10
WITH a(a) AS (VALUES (1), (2), (3), (4), (5)) SELECT sum(a) FROM a; -- 15
SELECT create_reducer('product', 'di', 'a*b', 'a', 'b');
SELECT product(1, 2, 3, 4); -- 24
WITH b(b) AS (VALUES (1), (2), (3), (4), (5)) SELECT product(b) FROM b; -- 120There is 3 flags possible.
dthe function is deterministicithe function is innocuous (i.e. does not cause side effects)Dthe function shall only be called directly (prevents it from being used in the likes ofCHECK,DEFAULTorTRIGGER)
git clone https://github.com/natnat-mc/sqlite-fn.git
cd sqlite-fn
make