LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

dolt-sql

execute SQL queries on versioned database

TLDR

Run SQL query
$ dolt sql -q "[SELECT * FROM table]"
copy
Start interactive SQL shell
$ dolt sql
copy
Execute a SQL file
$ dolt sql --file [script.sql]
copy
Run a query and choose the result format
$ dolt sql -q "[SELECT * FROM table]" -r [csv]
copy
Query a table as of another branch or commit
$ dolt sql -q "[SELECT * FROM table AS OF 'main']"
copy
Keep going after a failing statement
$ dolt sql --continue --file [script.sql]
copy
Save a query to the catalog and run it later by name
$ dolt sql -q "[SELECT * FROM table]" -s [my_query]
copy
$ dolt sql -x [my_query]
copy

SYNOPSIS

dolt sqldolt sql < script.sqldolt sql -q query [-r format] [-s name -m message]dolt sql -x namedolt sql --list-saved

DESCRIPTION

dolt sql is the primary way to read and write a Dolt database. It speaks MySQL-compatible SQL, so most existing queries, clients, and ORMs work unchanged.With no arguments it opens an interactive shell with history and tab completion. With -q it runs one statement and exits, which is the form used in scripts. Results can be rendered as a table, or as CSV, JSON, or Parquet for piping into other tools.Dolt's version control is exposed through SQL rather than through extra commands. `AS OF` reads a table at any branch, tag, or commit; `doltdiff<table>` and `dolthistory<table>` expose per-row change history; and system tables such as `doltlog`, `doltbranches`, and `doltstatus` mirror the CLI. Stored procedures like `CALL DOLTCOMMIT(...)` and `CALL DOLT_MERGE(...)` let an application commit and merge without ever leaving SQL.Writes made here land in the working set, exactly as if you had edited files in a Git checkout: they are not part of the history until they are staged and committed.

PARAMETERS

-q, --query QUERY

Run a single query and exit.
-r, --result-format FORMAT
How to format the output: `tabular` (default), `csv`, `json`, `vertical`, or `parquet`.
-f, --file FILE
Execute the statements in FILE.
-c, --continue
Keep running the remaining queries after one fails.
-s, --save NAME
Save the query to the query catalog under NAME.
-m, --message MSG
Store a descriptive message alongside a saved query.
-x, --execute NAME
Execute the saved query with the given name.
-l, --list-saved
List all saved queries.
--binary-as-hex / --skip-binary-as-hex
Print binary data as hex, or do not. Enabled by default on interactive terminals.
--disable-auto-gc
Do not run automatic garbage collection for this invocation.
-b, --batch
Retained as a no-op for compatibility; batch processing is no longer a separate mode.

CAVEATS

Compatibility with MySQL is high but not total: some functions, storage engines, and edge-case behaviours differ, and triggers, views, and stored procedures are supported to varying degrees depending on version. -b/--batch still parses but does nothing. A separate `dolt sql-server` process holds a lock on the database, so running the CLI shell against the same database while a server is up connects to that server rather than opening the files directly.

HISTORY

Dolt's SQL engine is go-mysql-server, a MySQL-compatible engine that DoltHub took over and heavily extended. Making SQL the interface, rather than a bespoke query language, is what allowed Dolt to slot into existing tooling, and the version-control surface was subsequently pushed into SQL as system tables and stored procedures so that applications could branch, diff, and merge data without shelling out.

SEE ALSO

dolt(1), dolt-commit(1), dolt-merge(1), mysql(1), sqlite3(1)

RESOURCES

Copied to clipboard
Kai