Skip to content

WebMacro

Load DuckDB SQL macros (scalar and table) from a remote URL.

29,367
extension loads Β· last 90 days
On this page

Technical Overview

One macro, distributed by URL

What this extension is for

  • β€’ One source of truth: Host the macro definition where your team already collaborates β€” a Git repo, an internal wiki that serves raw text, an S3 bucket, a private gist. Everyone calling load_macro_from_url gets the same SQL.
  • β€’ Version-controlled SQL: Pin a specific commit URL (e.g. https://raw.githubusercontent.com/org/repo/<sha>/macros/foo.sql) and you've got reproducible macro loading. Reviewable in pull requests; rollback is a URL change.
  • β€’ Session-start bootstrap: Load a handful of standard macros at the top of a notebook or script β€” one SELECT load_macro_from_url(url) FROM (VALUES (...)) call and the session has its toolbox.
  • β€’ Both scalar and table macros: DuckDB supports scalar MACRO and table MACRO. WebMacro loads either β€” whatever the URL's body parses as.

How it works

  • β€’ Plain HTTP(S) GET: Uses cpp-httplib with OpenSSL for TLS. Redirects are followed automatically (so a gist.github.com/... URL that 301s to gist.githubusercontent.com/... works). The read timeout is 10 seconds.
  • β€’ Substring validation: The fetched body must contain a CREATE [OR REPLACE] [TEMP|TEMPORARY] MACRO token. It's then scanned for dangerous keywords (DELETE, DROP, TRUNCATE, ALTER, GRANT, REVOKE, CREATE USER, EXEC, EXECUTE, SHUTDOWN, RESTART, DETACH); a hit raises an error. This is a substring check, not a SQL parser β€” treat it as a guardrail against accidentally fetching the wrong file, not a security boundary.
  • β€’ Session-scoped registration: The macro is created on the current DuckDB connection (using whatever scope the SQL itself declared β€” persistent, TEMP, or OR REPLACE). It lives until the session ends or the macro is dropped, just like a hand-typed CREATE MACRO.
  • β€’ WASM build: In DuckDB-WASM the extension uses a WASM-friendly HTTP shim instead of OpenSSL httplib β€” same function surface, browser-fetch under the hood.

Trust model

  • β€’ Only load from URLs you control: Your own Git repos, your team's internal artifact host, your own gists. Don't load from URLs found in chat messages, Stack Overflow, or random blog posts β€” same posture you'd use for curl ... | bash. See OWASP β€” Code Injection.
  • β€’ The dangerous-command filter is not a sandbox: It's a literal substring scan over the response body. It catches obvious things (DROP TABLE, DELETE FROM) but does not understand SQL β€” comments, string literals, and creative formatting all bypass it. A motivated author can bypass the filter; the filter is there to catch wrong-file-by-accident, not malice.
  • β€’ Pin URLs to immutable revisions: If you load from a Git host, prefer URLs with a commit SHA over branch names β€” .../<sha>/macros/foo.sql rather than .../main/macros/foo.sql. That way a compromised or rebased branch doesn't silently change what you load tomorrow.
  • β€’ TLS is on by default β€” keep it on: HTTPS prevents network-level tampering between your DuckDB and the macro host. Plain http:// URLs work but should be avoided outside of localhost / lab networks.
  • β€’ No cross-session caching: Every load_macro_from_url call hits the network. If the upstream changes, the next session sees the change. Pin URLs for reproducibility.

Common Use Cases

Deep Dive

Technical Details

Install

INSTALL webmacro FROM community;
LOAD webmacro;

Quick Start

Load a macro from a URL and use it

-- Pull a macro definition from a URL you control
SELECT load_macro_from_url(
  'https://raw.githubusercontent.com/your-org/sql-macros/main/search_posts.sql'
) AS res;

-- Use it like any other DuckDB macro
SELECT * FROM search_posts('qxip.bsky.social', text := 'quack');

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Name Description
Loading
load_macro_from_url() Fetch the URL, validate that the response body is a macro definition, register the macro in the current DuckDB connection, and return Successfully loaded macro: <name>.

API Reference

Function Documentation

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Experimental
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
29,367
loads Β· last 90 days

Platforms

Platform availability hasn't been recorded for this extension yet.

DuckDB & Haybarn

Release calendar
Not recorded for this extension.