sqlctx is CLI-first. The command line follows one contract across command families so it can be used interactively and safely composed in scripts. Online documentation: https://github.com/sidequery/sqlctx/blob/main/docs/cli.md. Support and bug reports: https://github.com/sidequery/sqlctx/issues.
Full help is available through every conventional entry point:
sqlctx -h
sqlctx --help
sqlctx help
sqlctx help migrate generate
sqlctx migrate generate -hsqlctx help accepts a nested command path and is equivalent to the
corresponding --help invocation.
Primary results and machine data go to stdout. Errors, warnings, deprecations,
and status messages go to stderr. This keeps pipelines such as
sqlctx info --json | jq .models valid.
The stable process exit codes are:
| Code | Meaning |
|---|---|
0 |
Success, including an empty but valid result |
1 |
An operation or validation failed |
2 |
The invocation or configuration is invalid |
Expected errors are concise. Put the global --debug option before the command
to let unexpected exceptions propagate with a traceback:
sqlctx --debug info ./modelsLong project, config, output, and diagnostic options can be placed before or after a subcommand. For example, these are equivalent:
sqlctx --project ./analytics info --format json
sqlctx info --project ./analytics --format jsonUse the long --quiet spelling after preagg recommend and preagg apply,
because those commands retain the existing -q shorthand for --queries.
Structured inspection and reporting commands accept --json, including:
sqlctx info --json
sqlctx init --json
sqlctx demo --json
sqlctx test --json
sqlctx validate --json
sqlctx validate --live --json
sqlctx dashboard validate dashboard.yml --json
sqlctx migrate check queries/ --json
sqlctx migrate generate queries/ --output generated/ --json
sqlctx preagg recommend --queries query-log.sql --json
sqlctx preagg apply --queries query-log.sql --dry-run --json
sqlctx preagg refresh --json
sqlctx explain "SELECT orders.revenue FROM orders"JSON is the only content written to stdout in these modes. Diagnostics remain on stderr.
Named consumption queries and result calculations use structured selectors:
sqlctx query --explore revenue_overview --models ./models --db data.duckdb
sqlctx query --saved-query paid_revenue --models ./models --db data.duckdb
sqlctx query --metric orders.revenue --dimension orders.region \
--filter "orders.status = 'paid'" --order-by "orders.revenue DESC" \
--limit 10 --table-calculation revenue_share --models ./models --db data.duckdbAn Explore supplies its default selection, filters, ordering and limit when those
options are omitted. Its allowlists, mandatory filters and maximum limit still
apply. Saved-query selections remain immutable. Use --user-attrs-file and
--enforce-visibility for the same caller and visibility checks as SQL queries.
Repeat --table-calculation to apply named calculations in order to the selected
result rows, after query ordering and pagination. Calculations reference selected
output columns or earlier calculations; they do not add hidden input fields.
Sequential calculations require --order-by or an Explore's default ordering.
--dry-run emits the SQL used by execution, including selected calculations.
Structured selectors cannot be mixed with a positional SQL query. Ordinary SQL queries retain their existing syntax and execution path.
Structured inspection, reporting, and query commands share one format option:
sqlctx query "SELECT status, order_count FROM orders" --format table
sqlctx query "SELECT status, order_count FROM orders" --format csv
sqlctx info --format json
sqlctx preagg recommend --queries queries.sql --format jsonl--format accepts table, csv, json, or jsonl. CSV emits a header,
JSON emits one complete value, and JSON Lines emits one object per record. The
existing --json spelling remains an alias for --format json on commands
that already offered it. Use --plain for stable, undecorated, tab-separated,
one-record-per-line output. Scripts should select --plain or an explicit
machine format instead of parsing the default human presentation.
--quiet/-q suppresses non-essential status and progress without suppressing
the requested result or errors. --verbose/-v enables detailed diagnostics;
--debug implies verbose diagnostics and includes unexpected tracebacks.
--version remains the unambiguous version option.
Color is enabled only for an interactive stream. --no-color, a non-empty
NO_COLOR, SQLCTX_NO_COLOR, or TERM=dumb disables it. A non-empty
FORCE_COLOR overrides automatic terminal detection, but not explicit disable
controls. Progress is animated only on an interactive stderr stream and is
disabled for redirects, machine formats, plain/quiet mode, and CI.
Update scripts to call sqlctx and use the SQLCTX_ environment variables.
New projects use sqlctx.yaml. Discovery also reads project configuration
files saved under the previous name.
Public sqlctx environment variables use the SQLCTX_ prefix:
| Variable | Meaning |
|---|---|
SQLCTX_PROJECT |
Project root used for discovery |
SQLCTX_CONFIG |
Explicit YAML or JSON config path |
SQLCTX_FORMAT |
Default table, csv, json, or jsonl output |
SQLCTX_PLAIN |
Enable plain output when truthy |
SQLCTX_QUIET |
Suppress non-essential diagnostics when truthy |
SQLCTX_VERBOSE |
Enable verbose diagnostics when truthy |
SQLCTX_DEBUG |
Enable debug tracebacks when truthy |
SQLCTX_NO_COLOR |
Disable sqlctx color when truthy |
SQLCTX_PAGER |
Pager command for long interactive reports |
SQLCTX_PG_PASSWORD_FILE |
PostgreSQL password credential file |
SQLCTX_API_AUTH_TOKEN_FILE |
HTTP API bearer-token credential file |
Ordinary settings use flag, environment variable, project config, then
built-in default precedence. Project config may define the same presentation
defaults under cli. Relative environment paths resolve from the working
directory; relative config paths resolve from the config file's directory.
Secrets use credential-file options, credential-file environment variables, or
- for stdin. Explicit credential-file options take precedence over
credential-file environment variables, then config credential paths. Do not
put secret values directly in environment variables.
Use - where a command accepts streamable SQL or a single generated file:
printf 'SELECT orders.revenue FROM orders\n' | sqlctx rewrite -
printf 'SELECT orders.revenue FROM orders\n' | sqlctx query - --output -
printf 'SELECT * FROM orders;\n' | sqlctx migrate check - --json
sqlctx generate client --output -
sqlctx convert models.yml --to sqlctx --output -
cat model.yml | sqlctx convert - --from sqlctx --to sqlctx --output -
cat model.sql | sqlctx convert - --from sqlctx --source-extension .sql --to sqlctx --output -rewrite, query, and explain read SQL from stdin when their SQL argument is
-. Migration and pre-aggregation query sources do the same. Query and
single-file code generation write to stdout when output is -.
For formats with multiple file syntaxes, stdin conversion infers JSON and native
sqlctx SQL when possible; use --source-extension to select explicitly.
Some exporters produce directories or multiple files, so they cannot stream to
stdout. migrate generate --output -, directory-only conversion inputs, and
multi-file/shape-dependent conversion targets fail with exit code 2 and a
specific explanation.
Never put a PostgreSQL server password or API bearer token directly in a command argument. Read it from a credential file:
sqlctx server postgres \
--username analytics \
--password-file .secrets/pg-password
sqlctx server api \
--auth-token-file .secrets/api-tokenBoth credential options accept - to read from stdin, which is useful with a
secret manager:
secret-tool lookup service sqlctx-api |
sqlctx server api --auth-token-file -Project configuration can point to the same files. Relative paths are resolved relative to the configuration file:
pg_server:
username: analytics
password_file: .secrets/pg-password
api_server:
auth_token_file: .secrets/api-tokenInline pg_server.password and api_server.auth_token configuration remains
supported for deployment systems that inject configuration securely. Prefer
credential files when the project configuration is shared or checked into
source control.
The old --password and --auth-token command-line options remain accepted for
compatibility but are hidden and deprecated because command arguments may be
visible to other processes. Their values are registered for output redaction,
and deprecation messages never contain the value. The flags will remain through
the 0.x line and are eligible for removal in 1.0 after at least one documented
release cycle. New command invocations should use credential files or stdin.
Use sqlctx help [COMMAND]... for nested offline help, or install the
generated sqlctx(1) manual page from the wheel. Long human-readable
reports support TTY-aware paging with --pager, --no-pager, and
SQLCTX_PAGER. Shell completion includes commands, semantic formats,
project model names, dashboard specs, and relevant paths.
See terminal help, paging, and completion for the complete contract. The CLI deprecation policy documents warning behavior, compatibility guarantees, replacements, and target removal releases.