Skip to main content

Install once, then call it from SQL

There is nothing to import at the call site. Install the extension once (left), then call the functions anywhere DuckDB takes a function (right).

duckdb
-- once per installation, then once per session
INSTALL duckfn_open FROM community;
LOAD duckfn_open;
duckdb
SELECT op_write_file(markdown, 'md'); -- content out to a file, its path back, nothing started
SELECT op_open_html('<h1>hello</h1>'); -- a temporary .html, opened in the default browser
SELECT op_sanitize_filename(report_title, '_'); -- a string in, a name every platform accepts out
SELECT op_open_path('report.html'); -- true once a launcher has been started
SELECT op_open_commands('report.html');
-- VARCHAR[]: the launch commands op_open_path would try on this machine, in order

Those trailing comments are the answers. The first two calls take a value that has no file yet, the last two a path that already exists — and the final one only lists the commands a launch would try, without trying any of them. In between, op_sanitize_filename is the one that stays a string: it rewrites a file name, touching neither the disk nor the desktop.

The full function reference