SQL Execution and Data Exploration
This page covers cz-cli commands for SQL execution, schema and table management, job diagnostics, and workspace switching.
cz-cli sql — Execute SQL
Basic Usage
Synchronous execution, returns results immediately (default):
Pass SQL with -e:
Read SQL from a file:
Synchronous vs Asynchronous
cz-cli sql runs synchronously by default (--sync), waiting for results before exiting. For long-running queries, submit asynchronously to get a job_id and retrieve results later:
Async submit, returns job_id immediately:
Check job status:
Or use the job command:
Write Protection
INSERT, UPDATE, DELETE, CREATE, DROP, and other write operations require the explicit --write flag to prevent accidental changes:
Batch Execution
Use --batch to execute multiple semicolon-separated statements in sequence:
Variable Substitution
Use --variable KEY=VALUE to inject variables; reference them in SQL with %(KEY)s. Useful for templated queries:
Query Hints
Use --set KEY=VALUE to pass query-level hints, such as setting the timezone:
Dry Run
Validate syntax and run EXPLAIN without actually executing — useful for pre-deployment checks:
Output Control
Do not truncate long fields:
Remove row limit (default is 100 rows):
Suppress column headers:
Specify output format:
Full Parameter Reference
| Parameter | Description | Default |
|---|---|---|
--sync / --no-sync | Wait synchronously for results | true |
--async | Async submit, returns job_id immediately | false |
--write | Allow write operations (DDL/DML) | off |
--batch / -B | Execute multiple semicolon-separated statements | false |
--variable KEY=VALUE | Variable substitution; use %(KEY)s in SQL | — |
--set KEY=VALUE | Query hint | — |
--dry-run | EXPLAIN only, no actual execution | false |
--timeout | Job timeout in seconds | 300 |
--limit / --no-limit | Auto-truncate to 100 rows | true |
--truncate / --no-truncate | Truncate long fields (3000 chars) | true |
--header / --no-header / -N | Output column headers | true |
-f, --file | Read SQL from a file | — |
-e, --execute | SQL string (equivalent to positional argument) | — |
--stdin | Read SQL from stdin | false |
--job-profile | Retrieve execution profile for a completed job | — |
--schema-context | Attach schema information to the response (for agent use) | false |
cz-cli schema — Schema Management
List all schemas:
View schema details (including table list):
Create a schema:
Drop a schema (requires confirmation):
cz-cli table — Table Management and Data Exploration
List all tables in the current schema:
List tables in a specific schema:
View table structure (columns, types, comments):
Preview table data (default 10 rows):
View row count and recent job statistics:
View table version history (Time Travel support):
Create a table from DDL:
Drop a table (requires confirmation):
cz-cli job — SQL Job Diagnostics
Asynchronously submitted queries return a job_id. Use the job command to track them:
View job status and execution summary:
Retrieve job query results (waits if still running):
View job execution profile (analyze performance bottlenecks):
cz-cli workspace — Workspace Switching
View current workspace:
List all available workspaces:
Temporarily switch workspace (this command only):
Persist the switch (save to profile):
Common Use Cases
Case 1: Explore a new table
Case 2: Debug a slow query
Submit asynchronously first:
Note the job_id, then check execution details:
Case 3: Execute DDL in CI/CD
Validate syntax with dry-run first:
Execute after confirming no issues:
Case 4: Templated queries (agent scenario)
Related Documentation
cz-cli Documentation
- Installation and Configuration Guide — Installation, profile configuration
- Studio Task Development and Operations — Task management, runs
- AI Agent Integration — Agent LLM configuration, natural language operations
Lakehouse Documentation
- Workspace — Workspace concepts, user management, permission model
- Compute Cluster — VCluster type selection, spec configuration
- Schema — Schema creation and management
- Time Travel — Historical version queries (the underlying mechanism behind
table history)
