Run a SQL query over the folder
folio_queryRun a read-only SQL SELECT across CSV, JSON, Parquet, SQLite, DuckDB files and Markdown documents exposed as tables, returning rows for counts, filters, joins, tasks, and links.
Instructions
Run one read-only DuckDB SELECT over the served folder's data files and its documents as tables, and return the rows. Use it for any question data answers - counts, filters, joins across CSV, JSON, Parquet, SQLite or DuckDB files - and for questions about documents as data: what links to a page (folio.links where target is its path), open tasks, documents of a kind by a field. To read what one reference written in a document shows, use folio_embed. Anything but one SELECT, a path outside the folder and a web address are refused; a query stops after 10 seconds. Answers {columns: [{name, type}], rows, total: the row count, absent when rows were cut, partial: true when rows were cut, files: the data files read}: rows stop at 5,000 or 16 MB, and a long cell is cut at 20,000 characters, fewer when there are more than 10 columns.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | One SELECT. A data file is a table named by its path in single quotes, relative to folder, from the served folder after a slash, or absolute under the served folder: 'data/daily.csv', 'archive.sqlite#readings', or 'queries/q.sql' for a query file's result; * and ** patterns read many files at once. Documents are folio.documents(path, filename: the name without its folder, title: the one h1 outside <details>, kind), folio.headings(path, line, level, text, anchor), folio.links(path, line, url, target, fragment, context), folio.tasks(path, line, done, text), folio.frontmatter(path, key, value), folio.tables(path, line, row, header, cells), and kind.<name>(path and a column per field the kind declares) | |
| folder | No | The folder the query runs from, relative to the served folder or absolute under it, such as reports/; quoted paths resolve against it. Omit for the served folder |