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 directly (default):
Pass SQL with -e:
Read SQL from a file:
Sync vs Async
cz-cli sql executes synchronously by default (--sync), waiting for results before exiting. For long-running queries, you can submit asynchronously, get the job_id, and then retrieve results:
Submit asynchronously, returns job_id immediately:
Check job status:
Or use the job command:
Write Protection
Write operations such as INSERT, UPDATE, DELETE, CREATE, and DROP require the explicit --write flag to prevent accidental modifications:
Batch Execution of Multiple Statements
Use --batch to execute multiple semicolon-separated statements in sequence:
Variable Substitution
Use --variable KEY=VALUE to inject variables, referenced in SQL with %(KEY)s, suitable for templated queries:
Query Hints
Use --set KEY=VALUE to pass query-level hints, such as specifying a timezone:
Pre-execution Validation (dry-run)
Performs only syntax checking and EXPLAIN without actually executing, suitable for pre-deployment validation:
Output Control
Do not truncate long fields:
Remove row limit (default 100 rows):
Do not output column names:
Specify output format:
Full Parameter Reference
| Parameter | Description | Default |
|---|---|---|
--sync / --no-sync | Wait synchronously for results | true |
--async | Submit asynchronously, returns job_id immediately | false |
--write | Allow write operations (DDL/DML) | Off |
--batch / -B | Execute multiple semicolon-separated statements in batch | false |
--variable KEY=VALUE | Variable substitution, referenced in SQL with %(KEY)s | — |
--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 characters) | true |
--header / --no-header / -N | Whether to output column names | true |
-f, --file | Read SQL from file | — |
-e, --execute | SQL string (equivalent to positional argument) | — |
--stdin | Read SQL from stdin | false |
--job-profile | Query execution profile of a completed job | — |
--schema-context | Attach schema information to 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 (column names, types, comments):
Preview table data (default 10 rows):
View table 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:
Get 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 (current command only):
Persistent switch (saved to profile):
Common Use Cases
Scenario 1: Exploring a new table
Scenario 2: Debugging a slow query
Submit asynchronously first:
Note the job_id and view execution details:
Scenario 3: Executing DDL in CI/CD
Validate syntax with dry-run first:
Execute after confirming no issues:
Scenario 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 Related Documentation
- Workspace — Workspace concepts, user management, permission system
- Compute Cluster — VCluster type selection, specification configuration
- Schema — Schema creation and management
- Time Travel — Historical version queries (the underlying mechanism of the
table historycommand)
