Install and load
Run these commands in a Haybarn SQL session. The extension is available from the community repository.
INSTALL scalarfs FROM community;
LOAD scalarfs FROM community;
Try it in a temporary SQL session with scalarfs already loaded. Queries run in this tab; examples using files or services need their own setup.
Using upstream DuckDB? Follow the maintainer’s installation instructions.
Usage example
Read JSON from a variable
-- Read JSON from a variable
SET VARIABLE config = '{"debug": true, "port": 8080}';
SELECT * FROM read_json('variable:config');
-- Read CSV from inline content
SELECT * FROM read_csv('data+varchar:name,score
Alice,95
Bob,87');
-- Use a file path stored in a variable
SET VARIABLE data_path = '/data/reports/monthly.csv';
SELECT * FROM read_csv('pathvariable:data_path');
SET VARIABLE data_paths = ['/data/reports/monthly.csv', '/archive/reports/*.csv'];
SELECT * FROM read_csv('pathvariable:data_paths');
-- Write query results to a variable
COPY (SELECT * FROM my_table WHERE active) TO 'variable:exported' (FORMAT json);
SELECT getvariable('exported');
-- Store query results as native values (not serialized text)
COPY (SELECT path FROM files WHERE active) TO 'variable:paths' (FORMAT variable);
SELECT * FROM read_csv('pathvariable:paths'); -- Read all files from the list
-- Select which files to read via a catalog macro (pathmacro:)
CREATE TABLE reports AS
SELECT * FROM (VALUES ('west', '/data/west.csv'), ('east', '/data/east.csv')) t(region, path);
CREATE MACRO region_files(p) AS (SELECT list(path) FROM reports WHERE region = p['region']);
SET allowed_pathmacro_macros = 'region_files';
SELECT * FROM read_csv('pathmacro:region_files?region=east'); -- reads only the east file
-- Build pathmacro: URLs safely (keys/values URL-encoded)
SELECT to_pathmacro_url('region_files', {region: 'west'}); -- pathmacro:region_files?region=west
Provided by teaguesterling. Not yet verified on Haybarn 2.0.0.
Sample data & setupAbout this extension
DuckDB's file functions (read_csv, read_json, COPY TO, etc.) expect file paths. scalarfs bridges the gap when your content is already in memory, allowing the same functions to work with:
Variables — Store data in DuckDB variables and read/write them as files Path Variables — Use file paths stored in variables for dynamic file resolution Inline literals — Embed content directly in your queries without temporary files Catalog macros — Select which files to read from an index/catalog via a macro (pathmacro:)
Project overview from the community descriptor.
Documentation and resources
Project and build details
- Repository
- teaguesterling/duckdb_scalarfs
- License
- MIT
- Maintainers
- teaguesterling
- Written in
- C++
- Build source
16a2637eaab6- Build definition
- Community descriptor