sq data wrangler

sq is a command line tool that provides jq-style access to
structured data sources: SQL databases, or document formats like CSV or Excel.
It is the lovechild of SQL+jq.

sq executes jq-like queries, or database-native
SQL. It can join
across sources: join a CSV file to a Postgres table, or MySQL with Excel.
sq outputs to a multitude of formats
including JSON,
Excel, CSV,
HTML, Markdown
and XML, and can insert query
results directly to a SQL database.
sq can also inspect sources to view metadata about the
source structure (tables, columns, size). You can use sq diff
to compare tables, or entire databases. sq has commands for common database operations to
copy, truncate,
and drop tables.
Find out more at sq.io.
[!TIP]
The rest of this doc is mainly for sq end users and first-timers. Contributors
(bug reports, feature requests, pull requests), see CONTRIBUTING.md.
Drivers
sq knows how to deal with a data source type via a driver
implementation. To view the installed/supported drivers:
$ sq driver ls
DRIVER DESCRIPTION
sqlite3 SQLite
rqlite rqlite
duckdb DuckDB
postgres PostgreSQL
sqlserver Microsoft SQL Server
mysql MySQL
clickhouse ClickHouse
oracle Oracle
csv Comma-Separated Values
tsv Tab-Separated Values
json JSON
jsona JSON Array: LF-delimited JSON arrays
jsonl JSON Lines: LF-delimited JSON objects
xlsx Microsoft Excel XLSX
Install
macOS
brew install sq
[!NOTE]
sq is a core brew formula. The old
neilotoole/sq tap is retired. If you installed sq from it (brew install neilotoole/sq/sq),
the next brew update switches that install to the core formula.
Homebrew no longer builds bottles for Intel Macs, so on an Intel Mac, brew install sq builds
from source. To skip the build, download the macos-amd64 binary from
GitHub releases.
Linux
/bin/sh -c "$(curl -fsSL https://sq.io/install.sh)"
Windows
scoop bucket add sq https://github.com/neilotoole/sq
scoop install sq
Source
Prefer a package manager above, or a release binary.
go install needs the SQLite build tags, and its binary reports version v0.0.0-dev; use
make install from a clone for a version-stamped build.
go install -tags "sqlite_vtable sqlite_stat4 sqlite_fts5 sqlite_introspect sqlite_json sqlite_math_functions" \
github.com/neilotoole/sq@latest
Docker
The ghcr.io/neilotoole/sq
image is preloaded with sq and a handful of related tools like jq. The same
image is published to Docker Hub as
neilotoole/sq. Both are cosign-signed
and carry SLSA build provenance and an SPDX SBOM.
Local
# Shell into a one-time container.
$ docker run -it ghcr.io/neilotoole/sq zsh
# Start detached (background) container named "sq-shell".
$ docker run -d --name sq-shell ghcr.io/neilotoole/sq
# Shell into that container.
$ docker exec -it sq-shell zsh
Kubernetes
Running sq in a Kubernetes environment is useful for DB migrations,
as well as general data wrangling.
# Start pod named "sq-shell".
$ kubectl run sq-shell --image ghcr.io/neilotoole/sq
# Shell into the pod.
$ kubectl exec -it sq-shell -- zsh
See other install options.
Agent skills