跳到主要内容

装一次,之后就在 SQL 里调用

调用处不用 import 任何东西。左边装一次,右边就能在任何能写 DuckDB 函数的地方用它。

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

后面那些注释就是每次调用的答复:前两个递进去的是一个还没有文件的值,后两个是已经存在的路径 —— 最后一行只列出真去启动时会依次尝试的命令,一条都不尝试。中间那个停在字符串里:op_sanitize_filename 改写的只是文件名,既不碰磁盘,也不碰桌面。

完整的函数参考