Execute functions in the QuickJS DuckDB extension
Function category
Execute
2 functionsRun JavaScript code from SQL — `quickjs(...)` for general expressions and array → table fan-out, `quickjs_eval(fn, ...args)` for invoking a JS function with positional arguments and getting JSON back.
Signature
2 overloaded forms · click to inspectArguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
code
|
Type
VARCHAR
|
Mode Positional | Description |
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
code
|
Type
VARCHAR
|
Mode Named | Description |
Argument
varargs
|
Type
ANY
|
Mode Positional | Description Varargs |
Description
Evaluate JavaScript code and return the result. Has both a scalar form (returns a single value as VARCHAR) and a table-valued form (when the JS returns an array, each element becomes a row).
1
Simple expression
SELECT quickjs('2 + 2');
2
Array → table
SELECT * FROM quickjs('[1, 2, 3, 4, 5]');
3
Array with parameter passthrough
SELECT * FROM quickjs('parsed_arg0.map(x => x * arg1)', '[1, 2, 3, 4, 5]', 3);
Related functions
Signature
quickjs_eval(function: VARCHAR, varargs: ANY) → JSON
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
function
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
varargs
|
Type
ANY
|
Mode Positional | Description Varargs |
Description
Call a JavaScript function with the given arguments. The first argument is a JS function expression; subsequent arguments are passed positionally. The result is serialized as JSON.
1
Two-argument adder
SELECT quickjs_eval('(a, b) => a + b', 5, 3);
2
Custom JSON munging — better than chaining json_extract_*
SELECT quickjs_eval('(payload) => { const d = JSON.parse(payload); return { user: d.user, os: d.meta.os }; }', payload) AS extracted FROM events;