Skip to content

Loading functions in the WebMacro DuckDB extension

Function category

Loading

1 function

Fetch 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.

load_macro_from_url

Scalar function Loading
Signature
load_macro_from_url(url: VARCHAR) VARCHAR
Arguments (Positional)
Argument url Type VARCHAR Mode Positional Description HTTP or HTTPS URL whose response body is a SQL CREATE MACRO statement (scalar or table macro). Redirects are followed; any non-200 response raises an error.
Description
1 Load a macro from a Git-hosted raw URL
SELECT load_macro_from_url(
  'https://raw.githubusercontent.com/your-org/sql-macros/main/search_posts.sql'
) AS res;
-- 'Successfully loaded macro: search_posts'
2 Use the macro after loading
SELECT load_macro_from_url('https://quacks.cc/r/search_posts');

SELECT *
FROM search_posts('qxip.bsky.social', text := 'quack');
3 Load several macros at session start
SELECT load_macro_from_url(url) AS status
FROM (VALUES
  ('https://raw.githubusercontent.com/your-org/sql-macros/main/search_posts.sql'),
  ('https://raw.githubusercontent.com/your-org/sql-macros/main/normalize_handle.sql'),
  ('https://raw.githubusercontent.com/your-org/sql-macros/main/active_users.sql')
) AS macros(url);