Loading functions in the WebMacro DuckDB extension
Function category
Loading
1 functionFetch a SQL macro definition from an HTTP(S) URL and register it in the current DuckDB session. The whole extension is one function — point it at a URL that returns CREATE MACRO ... SQL.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
url
|
Type
VARCHAR
|
Mode Positional |
Description
https:// URL whose response body is one SQL CREATE MACRO statement (scalar or table macro). Redirects are followed, and each hop is checked again; any non-200 response raises an error. On DuckDB 2.0, plain http:// is refused unless SET webmacro_allow_http = true.
|
Description
Fetch the URL, check that the response body is a macro definition, create the macro, and return Successfully loaded macro: <name>. The macro is then callable by name like any other DuckDB macro.
The response body must be exactly one CREATE MACRO or CREATE OR REPLACE MACRO statement. Anything else raises an error and nothing runs, including a macro followed by another statement. The check covers what runs when the file loads, not what the macro does when you call it, so the security model is trust the URL. See the Trust model section.
DuckDB 2.0 build: the request goes through DuckDB's HTTP stack (httpfs is autoloaded for https://), so http_timeout, http_retries, http_proxy and HTTP secrets apply. Plain http:// is refused unless webmacro_allow_http is set, responses over webmacro_max_response_size bytes (default 1 MiB) are refused, and the function refuses to run when enable_external_access is false. The macro is created in your own transaction and search path, so TEMP macros work and a ROLLBACK removes the macro. The function is VOLATILE. The Haybarn 1.5 build still creates the macro on a separate connection and rejects TEMP macros.
SELECT load_macro_from_url(
'https://raw.githubusercontent.com/Query-farm/sql-macros/main/macros/search_posts.sql'
) AS res;
-- 'Successfully loaded macro: search_posts'
SELECT load_macro_from_url('https://quacks.cc/r/search_posts');
SELECT *
FROM search_posts('qxip.bsky.social', text := 'quack');
SELECT load_macro_from_url(url) AS status
FROM (VALUES
('https://raw.githubusercontent.com/Query-farm/sql-macros/main/macros/search_posts.sql'),
('https://raw.githubusercontent.com/Query-farm/sql-macros/main/macros/normalize_handle.sql'),
('https://raw.githubusercontent.com/Query-farm/sql-macros/main/macros/active_users.sql')
) AS macros(url);