usql Universal SQL CLI
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
usql <dsn>
usql sq://app.db
usql <dsn> -c "<sql>"
usql <dsn> -f <file>
\dt\d <name>\x auto\qConcepts
- DSN driver://user:pass@host/db
- Driver chosen by scheme or alias
- Prompt SQL plus \commands
- Output table, CSV, JSON, HTML
| Database | Scheme | Alias |
|---|---|---|
PostgreSQL |
postgres | pg |
MySQL |
mysql | my |
SQL Server |
sqlserver | ms |
Oracle |
oracle | or |
SQLite3 |
sqlite3 | sq |
DuckDB |
duckdb | dk |
ClickHouse |
clickhouse | ch |
Connect
usql pg://user:pass@host/db
usql my://user:pass@host:3306/db
usql sq://<path>.db
usql <path>
\c <dsn or name>
\driversRun and script
usql <dsn> -c "<sql>"
usql <dsn> -f <file>
\i <file>\g\p\r\e\begin / \commit / \rollback
Inspect the schema
\dt[S+] [<pattern>]
\d[S+] [<name>]
\dn [<pattern>]
\l[+]Output formats
-C-J-x-t\x [on|off|auto]
\GVariables and scripting
\set <name> <value>
:<name> / :'<name>' /
:"<name>"
\gexec\if <expr> / \elif / \else / \endif
`<command>`
\cset <name> <dsn>
\? [options|variables]
helpCopy and config
\copy <src> <dst> <query>
<table>
~/.config/usql/config.yaml
connections: { <name>: <dsn> }
init: |usql --versionusql --helpRecipes
usql sq://app.db -C -c "select * from users" > users.csv
usql pg://localhost/app -J -c "select id, name from users" | jq .
usql -c "\copy pg://localhost/src my://localhost/dst 'select * from t' t"
usql pg://localhost/app -1 -v id=42 -f fix.sql
# ~/.config/usql/config.yamlconnections: prod: pg://app@db.example.com/app dev: sq://dev.dbusql prod -c '\dt'



