UNSeQueL
Home / Documentation / CLI reference

CLI reference

All commands take a query file, or - to read the query from stdin. Exit code 0 means success, 1 a query/data error (or a failed fmt --check), and 2 a usage error.

Commands

CommandWhat it does
unsequel run <file | ->Execute the whole program and print the result.
unsequel check <file>Parse the program; with a schema, validate column/type usage too.
unsequel compile <file>Print the generated DuckDB SQL (one CTE per lowering unit).
unsequel preview <file> --stage NRun the program truncated at grammar stage N and show sample rows with the stage label.
unsequel fmt <file>Print the canonical form; --write rewrites, --check exits 1 if not canonical.
unsequel replInteractive session; a query runs on a blank line, a lone ;, or .run.

A bare unsequel on a terminal also opens the REPL. unsequel --version and unsequel --help are always available.

File directives

# source orders: ../data/orders.csv
# source products: ../data/products.csv
# schema: ../data/schema.json
from orders
join products on orders.product_id = products.product_id
select order_id, product_name

Directives must be the first lines of the file (no blank line or ordinary comment before them) and paths are resolved relative to the query file. --data overrides a directive with the same name; --schema overrides # schema:. Without any schema, tables loaded from the sources are introspected automatically, so run, compile, and preview work without a schema file. The formatter preserves directives.

Flags

FlagUsed byMeaning
--data name=pathrun, compile, preview, replLoad a CSV/JSON/Parquet file as a table; repeatable. Without name=, the table name is derived from the file name.
--schema pathrun, check, compile, preview, replJSON schema for pre-execution validation; overrides # schema:.
--lines A:Ball query commandsRun only the 1-based line range (the file's directives still apply).
--stage Ncompile, previewTruncate at grammar stage N. Required for preview; counts stages, not CTEs.
--limit KpreviewSample rows to show (default 10).
--format table|json|csvrun, preview, replOutput format (default table).
--delimiter Crun, compile, preview, replOne-character CSV delimiter (default comma). Applies to all loaded CSVs.
--column-type table.column=typerun, compile, preview, replOverride CSV/JSON column inference; repeatable. Types: text, integer, number, boolean, date, time, timestamp, decimal(p,s).

Examples

# run a self-contained file
unsequel run examples/real/r01_top_products.unsequel

# run just the selected lines of a multi-query file
unsequel run queries.unsequel --lines 12:20

# query from stdin (needs --data because stdin has no directives)
echo "from orders | take 1" | unsequel run - --data orders=examples/spec/orders.csv

# step through a pipeline: show the relation after stage 4
unsequel preview query.unsequel --stage 4 --limit 5

# inspect the generated SQL
unsequel compile query.unsequel --stage 4

# non-comma CSV with an explicit type override
unsequel run query.unsequel --delimiter ';' --column-type orders.postal_code=text

# JSON output
unsequel run query.unsequel --format json

REPL commands

CommandMeaning
.runExecute the query being typed now.
.load name=pathLoad a CSV/JSON/Parquet file as a table.
.sourcesList loaded sources.
.schema [path]Show or set an explicit schema file.
.format table|json|csvChange the output format.
.clearDiscard the query being typed.
.quitExit (warns if lines are pending).