query
tonic query is the direct SQL execution surface.
tonic query ping --target warehouse--target is required. The output includes the resolved target name, backend, and configured context.
Execute Inline SQL
Section titled “Execute Inline SQL”tonic query exec \ --target warehouse \ --sql 'select * from reports.daily_sales'Rules:
- Exactly one of
--sqlor--fileis required. --targetis required with--sql.- Inline SQL must contain exactly one statement after comments and whitespace are stripped.
- Inline transaction-control statements are rejected.
- Statement support and permissions are checked before a session opens.
Execute A Query File
Section titled “Execute A Query File”tonic query exec --file reports.sql--target is optional with --file; it acts as a fallback when the file does not declare a target with tonic-file.
tonic query exec --target warehouse --file reports.sqlFile execution runs statements sequentially and stops on the first error. Table and CSV output is written as each statement finishes, so completed results remain visible while later statements run or if one fails. JSON output is buffered until the file finishes so it remains one valid document.
Query files may include printable report comments. Human formats render tonic-print text directly around statement results; JSON output includes typed events plus the statement result list.
-- tonic-print: # Daily sales report-- tonic-print:select * from reports.daily_sales;Context Overrides
Section titled “Context Overrides”tonic query exec \ --target warehouse \ --context schema=analytics \ --sql 'select count(*) from daily_sales'Context keys are backend-aware. For example, Snowflake accepts database, schema, warehouse, and role; DuckDB accepts database and schema; SQLite accepts none.
Autocommit
Section titled “Autocommit”tonic query exec \ --target warehouse \ --autocommit off \ --sql 'update jobs set touched_at = current_timestamp where id = 1'Valid values are on and off. The default is on.
For query files, --autocommit is the fallback for reusable sessions that do not declare autocommit in tonic-file or tonic-bind.
Formats
Section titled “Formats”tonic query exec --target warehouse --format table --sql 'select 1'tonic query exec --target warehouse --format csv --sql 'select 1'tonic query exec --target warehouse --format json --sql 'select 1'Command-like results render status, target, statement, and rows affected. Row-producing results render columns and rows.