Install and load
Run these commands in a Haybarn SQL session. The extension is available from the community repository.
INSTALL ducktinycc FROM community;
LOAD ducktinycc FROM community;
Using upstream DuckDB? Follow the maintainer’s installation instructions.
Usage example
Compile a C function and register it as collatz_steps(BIGINT) -> BIGINT
-- Compile a C function and register it as collatz_steps(BIGINT) -> BIGINT
SELECT ok, code
FROM tcc_module(
mode := 'quick_compile',
source := 'int64_t collatz_steps(int64_t n) {
int64_t steps = 0;
if (n < 1) return -1;
while (n != 1) { n = (n & 1) ? 3 * n + 1 : n / 2; steps++; }
return steps;
}',
symbol := 'collatz_steps',
sql_name := 'collatz_steps',
return_type := 'i64',
arg_types := ['i64']
);
-- Longest Collatz chain below one million: 837799, 524 steps
SELECT arg_max(range, collatz_steps(range)) AS n, max(collatz_steps(range)) AS steps
FROM range(1, 1000000);
-- Every DuckTinyCC function, mode, type token, and C helper
SELECT kind, name, description FROM tcc_help();
Provided by sounkou-bioinfo. Not yet verified on Haybarn 2.0.0.
Sample data & setupAbout this extension
DuckTinyCC compiles C from SQL using TinyCC (libtcc), in-process, and registers it as a scalar, aggregate (kind := 'aggregate'), or table function (kind := 'table'). SELECT * FROM tcc_help() lists every function, tcc_module mode, type token, and C helper with an example. Worked examples: https://sounkou-bioinfo.github.io/DuckTinyCC/cookbook.html
Project details and examples: https://github.com/sounkou-bioinfo/DuckTinyCC
Project overview from the community descriptor.
Documentation and resources
Project and build details
- Repository
- sounkou-bioinfo/DuckTinyCC
- License
- MIT
- Maintainers
- sounkou-bioinfo
- Written in
- C
- Build source
6471af8132ff- Build definition
- Community descriptor