/sq:sqfrom sq
Queries SQL databases and data files (CSV, TSV, JSON, Excel) from the command line using SLQ or native SQL, with cross-source joins and result writing to another database.
Ships in sq. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
sq queries SQL databases and data files with SLQ, a jq-like language, or with
native SQL, and writes the results as text, JSON, CSV, Excel and more, or into
another database. Docs: sq.io. This skill is for using an
installed sq; sq <command> --help is authoritative for flags.
Each data source has a handle such as @sakila_pg. sq add creates one:
sq add ./data.csv # handle derived from the name: @data
sq add 'postgres://[email protected]/sakila' -p --handle @pg # prompts for the password
sq add https://sq.io/testdata/actor.csv # remote file, downloaded
sq ls # list sources; -j for JSON
sq src @pg # set the active source
sq ping @pg
sq rm @pg; sq mv @pg @prod/pg # remove; rename (groups: @group/name)
A query without a handle runs against the active source. --src @h
overrides it for one command, and --src.schema picks a schema (and/or
catalog) for one command.
-p prompts, which an agent cannot answer. Use one of these instead:
# A placeholder, resolved at connect time. Schemes: env, file, keyring, op.
# The config stores only the reference, never the password.
sq add 'postgres://alice:${env:DB_PASSWORD}@db/sakila'
sq add 'postgres://alice:${file:/run/secrets/db_pw}@db/sakila'
# -p reads the password from stdin when stdin has input. The password is then
# stored in the config file, unless you also pass --store keyring.
sq add 'postgres://alice@db/sakila' -p <<< "$DB_PASSWORD"
Prefer a placeholder for anything that matters.
Single-quote placeholders so the shell does not expand them. sq add resolves
the placeholder to detect the driver, so the secret must be available then, or
pass --driver. --store keyring saves the secret in the OS keyring instead of
the config file. Output redacts passwords; --reveal shows them and --expand
resolves placeholders. See Secrets.
A query is a pipeline of segments: a table, then filters, columns, and so on.
sq '@sakila.actor | .first_name, .last_name | .[0:10]' # columns, first 10 rows
sq '@sakila.actor | where(.actor_id < 3 && .first_name != "NICK")' # filter
sq '@sakila.actor | where(startswith(.last_name, "B"))' # string match
sq '@sakila.film | order_by(.length-) | .title, .length' # sort; trailing - is descending
sq '@sakila.film | group_by(.rating) | .rating, count' # group
sq '@sakila.payment | sum(.amount), avg(.amount), max(.amount)' # aggregates
sq '@sakila.actor | count' # row count
sq '@sakila | .actor | join(.film_actor, .actor_id)' # join on a shared column
sq '@csv_people.data, @pg.address | join(.uid)' # join across sources
sq --render-sql '@sakila.actor | .[0:2]' # show the SQL, don't run it
File sources expose their rows as the table .data; an Excel source has one
table per sheet. String functions: contains, startswith, endswith, like
(SQL wildcards), each with a case-insensitive i form (icontains). Aggregates:
count, count_unique, sum, avg, min, max. Full syntax:
Query language.
Native SQL goes through sq sql, which also runs statements:
sq sql --src @pg 'SELECT COUNT(*) AS n FROM film'
sq sql --src @pg --insert @local.recent 'SELECT * FROM rental WHERE rental_date > now() - interval '"'"'7 days'"'"''
Default output is a text table. Format flags: -j JSON, -J JSON Lines, -A
JSON arrays, -C CSV, --tsv, -y YAML, --xml, --markdown, --html,
-x XLSX, -r raw; -H drops the header row, -c compacts, -o FILE writes
to a file. See Output.
sq -j '@sakila.actor | .[0:5]' # JSON for parsing
sq -x '@sakila.actor' -o actor.xlsx # Excel file
sq --insert @pg.actor_copy '@sakila.actor' # write rows to a table (created if missing)
To write into a new local database, add an empty SQLite file first:
sq add --driver=sqlite3 ./out.db --handle @out, then --insert @out.tbl.
For programmatic use, prefer -j and --error.format json; errors then go to
stderr as {"error": "..."}.
sq reads a file from stdin and queries it as .data (or by sheet for Excel).
Detection can fail on short input; name the driver with --ingest.driver:
cat people.csv | sq --ingest.driver=csv '.data | .name, .email'
cat data.xlsx | sq '.sheet1 | .[0:10]'
| Command | Purpose |
|---|---|
sq inspect @h / @h.table | Schema, columns, row counts. -j for JSON. Docs |
sq inspect @h -f mermaid-erd | Entity-relationship diagram; also --markdown, --html, -f svg-erd, -f png-erd |
sq diff @a @b (BETA) | Compare metadata or row data of sources or tables. Docs |
sq tbl copy / truncate / drop | Table operations. Copy |
sq db exec / dump / restore | Run a SQL script; dump or restore a database with the engine's own tools |
sq driver ls | Drivers in this build |
sq config ls / get / set | Options. Config |
sq cache clear @h | Drop cached ingest data for a file source (stale results after a file change) |
When the task involves a specific driver (connection strings, versions, caveats), open its reference file:
Driver (sq driver ls) | Reference |
|---|---|
sqlite3 | references/sqlite3.md |
duckdb | references/duckdb.md |
postgres | references/postgres.md |
mysql | references/mysql.md |
sqlserver | references/sqlserver.md |
clickhouse | references/clickhouse.md |
oracle | references/oracle.md |
rqlite | references/rqlite.md |
csv | references/csv.md |
tsv | references/tsv.md |
json | references/json.md |
jsona | references/jsona.md |
jsonl | references/jsonl.md |
xlsx | references/xlsx.md |
references/clickhouse.md (opens in a new tab)references/csv.md (opens in a new tab)references/duckdb.md (opens in a new tab)references/json.md (opens in a new tab)references/jsona.md (opens in a new tab)references/jsonl.md (opens in a new tab)references/mysql.md (opens in a new tab)references/oracle.md (opens in a new tab)references/postgres.md (opens in a new tab)references/rqlite.md (opens in a new tab)references/sqlite3.md (opens in a new tab)references/sqlserver.md (opens in a new tab)references/tsv.md (opens in a new tab)references/xlsx.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
SQL, PostgreSQL, MySQL, SQLite, DuckDB, ClickHouse, Oracle, SQL Server
npx claudepluginhub neilotoole/sq --plugin sqOther plugins' skills for the same job