dolt-sql
Execute SQL queries against Dolt databases
TLDR
Run a single query
List all saved queries
SYNOPSIS
dolt sql [OPTIONS] [QUERIES...]
PARAMETERS
-c, --continue-on-error
Continue processing queries after an error
-h, --help
Display help for sql
-j, --json
Output results as JSON objects
-o, --ordered
Produce stable result ordering using table row primary keys
-q, --query string
Query to execute (may be repeated); implies non-interactive mode
-r, --results-dir string
Directory to write query results as CSV/JSON
-s, --stats
Print query execution statistics
-t, --thread int
Number of threads for query execution (default 1)
-v, --verbose
Print verbose logs to stderr
--version
Print version information
DESCRIPTION
The dolt sql command provides a powerful SQL interface to Dolt, a version-controlled database that combines the familiarity of SQL with Git-like versioning for tables, schemas, and branches.
Dolt enables data teams to collaborate using familiar tools like pull requests, diffs, and merges. dolt sql serves as both an interactive REPL for ad-hoc querying and a non-interactive executor for scripts or automation.
In interactive mode (invoked without -q), it offers multi-line editing, autocompletion, and history. Queries can read from or write to Dolt tables, with support for Dolt-specific SQL extensions like SELECT * FROM dolt_status to view diffs.
Non-interactively, pipe SQL or use -q flags for batch processing. Output formats include tabular (default), JSON (-j), or CSV to files via --results-dir. It leverages MySQL-compatible syntax and wire protocol, allowing connections from tools like MySQL Workbench.
Key features: parallel query execution (--thread), error handling (--continue-on-error), stable ordering (--ordered), and verbose logging. Always run within a Dolt repository initialized via dolt init.
Ideal for data engineering, analytics, and ML workflows requiring version control.
CAVEATS
Must be run inside a Dolt repository; Dolt-specific SQL functions require Dolt version; JSON output flattens nested results; large result sets may consume significant memory without --results-dir.
INTERACTIVE MODE
Omit -q for REPL with tab completion, history (\s for status), and \q to quit.
Supports Dolt system tables like dolt_history.
EXAMPLES
dolt sql -q "SELECT * FROM mytable"
dolt sql -j -q "SELECT name, COUNT(*) FROM users GROUP BY name"
echo 'CREATE TABLE t (pk INT PRIMARY KEY);' | dolt sql
HISTORY
Introduced with Dolt v0.1.0 in 2019 by DoltHub; evolved to support MySQL 8.0+ compatibility, parallel execution in v1.0 (2022), and enhanced diff queries. Actively maintained as core Dolt tool.


