query

Execute a single SQL statement and print the result set.

Category: commands

Syntax

delta-forge-cli query [--node <name>] [--with-plan] <SQL>...

Description

## Overview `query` executes a single SQL statement against the compute engine and renders the result set in the selected output format. It is the canonical one-shot invocation, intended for scripting, ad-hoc inspection, and agent-driven automation where composing multiple statements in one call is not required. ## Behavior - All positional arguments after `query` are joined with a single space. `delta-forge-cli query SELECT count(*) FROM t` and `delta-forge-cli query 'SELECT count(*) FROM t'` both execute the same statement. - The CLI authenticates once at startup and sends the statement as a single SSE-backed request. There is no session-level state carried across invocations. - When `--node` is passed, the display name or `entity_ref` is resolved to a compute URL via `/list-compute-nodes` and used for this request only. - Output format is selected by the global `--format` flag. `table` renders a Unicode-bordered grid, `compact` renders borderless rows, and `json` emits `{ columns, rows, rowCount, executionTimeMs }`. - For statements that produce no result set (DML, DDL), the CLI prints a single `OK (<elapsed>ms)` line using the engine's returned message if any. - Exit code: `0` on success, `1` on SQL error or auth failure, `2` on client-initialisation failure (bad URL, HTTP client construction). - When stdin is a TTY and credentials are not explicit, an inline stdin prompt collects username and password. In non-TTY contexts, missing credentials fail with an authentication error. ## Compatibility - `query` does not support multi-statement scripts. Pass multiple statements via `run` or by piping to `delta-forge-cli` without a subcommand. - The statement runs through the same executor used by the REPL and by `run`, so dialect and function coverage are identical across surfaces.

Parameters

NameTypeDescription
SQLOne or more words joined by whitespace forming the SQL statement. The CLI collects positional arguments and joins them with a single space before execution, so shell quoting and escaping rules apply.
--nodeCompute node display name or `entity_ref`. Resolved against the control plane's `/list-compute-nodes` endpoint and pins the query to that node for this invocation. Overrides the global `--node` flag.
--with-planWhen set, runs the query normally and then issues a second `include_plan: true` call against the same compute node. The physical plan is printed to stderr after the result table so stdout stays pipe-friendly. Equivalent to running `delta-forge-cli plan` separately. See the `plan` subcommand for finer control over plan type and format.

Examples

# Basic scalar query
delta-forge-cli query SELECT count(*) FROM sales.orders WHERE status = 'shipped'
# JSON output for downstream parsing
delta-forge-cli --format json query SELECT * FROM sales.products LIMIT 10
# Pin to a specific worker
delta-forge-cli query --node prod-worker-01 SELECT * FROM analytics.daily_revenue
# Use a profile for connection details
delta-forge-cli --profile production query SHOW TABLES IN sales
# Pipe into jq to extract a scalar
delta-forge-cli --format json query SELECT count(*) FROM orders | jq -r '.rows[0][0]'
# DML statements print a 'OK (<ms>)' line instead of a table
delta-forge-cli query UPDATE sales.orders SET status='closed' WHERE id=42

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →