Skip to content
DuckDB community extension

func_apply

Dynamic function invocation - call any scalar function or macro by name at runtime

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL func_apply FROM community;
LOAD func_apply FROM community;

Try it in a temporary SQL session with func_apply already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Call scalar functions dynamically

SQL
-- Load the extension

-- Call scalar functions dynamically
SELECT apply('upper', 'hello world');
-- Result: HELLO WORLD

SELECT apply('substr', 'hello world', 7, 5);
-- Result: world

-- Call table functions dynamically
SELECT * FROM apply_table('range', 5);
-- Returns: 0, 1, 2, 3, 4

SELECT * FROM apply_table('generate_series', 1, 10, 2);
-- Returns: 1, 3, 5, 7, 9

-- Check if a function exists before calling
SELECT function_exists('my_custom_func');
-- Result: true/false

Provided by teaguesterling. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

The FuncApply extension enables dynamic function invocation in DuckDB, allowing you to call any scalar function or macro by name at runtime. This is useful for data-driven transformations, dynamic SQL generation, and building flexible data pipelines.

The '*' entry catches any key the map does not name. Unlike apply() with a function name that is not a constant, func_dispatch binds every candidate in a constant routing map at plan time, so the result keeps its real type instead of collapsing to VARCHAR:

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
teaguesterling/duckdb_func_apply
License
MIT
Maintainers
teaguesterling
Written in
C++
Build source
9f119877ef5c
Build definition
Community descriptor