usql is a universal command-line interface for PostgreSQL, MySQL, Oracle
Database, SQLite3, Microsoft SQL Server, and many other databases
including NoSQL and non-relational databases!
usql works with SQL and NoSQL databases from a command line
modelled on PostgreSQL's psql. usql supports most of the
core psql features, such as variables, backticks,
backslash commands and has additional features that psql does
not, such as multiple database support, copying between databases,
context-based completion,
and terminal graphics.
Database administrators and developers that would prefer to work with a tool
like psql with non-PostgreSQL databases, will find usql intuitive,
easy-to-use, and a great replacement for the command-line clients/tools
for other databases.
usql can be installed via Release, via Homebrew, via AUR, via
Go or via Docker:
- Download a release for your platform
- Extract the
usqlorusql.exefile from the.tar.bz2or.zipfile - Move the extracted executable to somewhere on your
$PATH(Linux/macOS) or%PATH%(Windows)
Install usql from the xo/xo tap in the usual way with the brew
command:
# install usql
$ brew install xo/xo/usqlSupport for ODBC databases is available through the --with-odbc
install flag:
# add xo tap
$ brew tap xo/xo
# install usql with odbc support
$ brew install --with-odbc usqlInstall usql from the Arch Linux AUR in the usual way with the
yay command:
# install usql
$ yay -S usql-binusql-bin installs the released binary. To build from source instead, use the
usql package, which takes considerably longer because it compiles
every driver:
# build usql from source
$ yay -S usqlAlternately, build and install using makepkg:
$ git clone https://aur.archlinux.org/usql.git && cd usql
$ makepkg -siInstall usql in the usual Go fashion:
# install the latest usql version, with every driver
$ go install github.com/xo/usql@latestSee below for information on the build tags that leave drivers out.
An official container image (docker.io/usql/usql) is maintained
by the usql team, and can be used with Docker, Podman, or other container
runtime.
Install usql with Docker, Podman, or other container runtime:
# run interactive shell and mount the $PWD/data directory as a volume for use
# within the container
$ docker run --rm -it --volume $(pwd)/data:/data docker.io/usql/usql:latest sqlite3://data/test.db
Trying to pull docker.io/usql/usql:latest...
Getting image source signatures
Copying blob af48168d69d8 done |
Copying blob efc2b5ad9eec skipped: already exists
Copying config 917ceb411d done |
Writing manifest to image destination
Connected with driver sqlite3 (SQLite3 3.45.1)
Type "help" for help.
sq:data/test.db=> \q
# run postgres locally
$ docker run --detach --rm --name=postgres --publish=5432:5432 --env=POSTGRES_PASSWORD=P4ssw0rd docker.io/usql/postgres
# connect to local postgres instance
$ docker run --rm --network host -it docker.io/usql/usql:latest postgres://postgres:P4ssw0rd@localhost
Connected with driver postgres (PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1))
Type "help" for help.
pg:postgres@localhost=> \q
# run specific usql version
$ docker run --rm -it docker.io/usql/usql:0.21.5usql has one build. A go build or go install with no build tags includes
every driver and the chart renderer:
# build/install with every driver
$ go install github.com/xo/usql@mainEach driver has a build tag, which the table of drivers lists in
its Scheme / Tag column. The build tag no_<tag> leaves that driver out:
# build/install every driver except Avatica, Couchbase and PostgreSQL
$ go install -tags 'no_avatica no_couchbase no_postgres' github.com/xo/usql@mainThe build tag no_drivers leaves out every driver. Name a driver by its tag
to put it back:
# build/install with only the SQLite3 driver
$ go install -tags 'no_drivers sqlite3' github.com/xo/usql@main
# build/install with only the PostgreSQL and MySQL drivers
$ go install -tags 'no_drivers pgx mysql' github.com/xo/usql@mainno_drivers also leaves out the chart renderer. Add the tag charts to keep
it. The tag no_charts leaves it out of any build.
usql works with all Go standard library compatible SQL drivers supported by
github.com/xo/dburl.
The list of drivers that usql was built with can be displayed with the
\drivers command:
$ cd $GOPATH/src/github.com/xo/usql
# build with only the cassandra, moderncsqlite and mysql drivers
$ go build -tags 'no_drivers cassandra moderncsqlite mysql'
# show built driver support
$ ./usql -c '\drivers'
Available Drivers:
cassandra [ca, cql, scy, cass, scylla, datastax]
moderncsqlite [sq, mq, sqlite, sqlite3, modernsqlite]
mysql [my, maria, aurora, mariadb, percona]The above shows that usql was built with only the cassandra,
moderncsqlite and mysql drivers. Each line names the scheme of a driver,
and its aliases in [...]. Without sqlite3, moderncsqlite also answers to
the sqlite3 scheme and its aliases.
The following are the Go SQL drivers that usql supports, the
associated database, scheme / build tag, and scheme aliases:
| Database | Scheme / Tag | Scheme Aliases | Driver Package / Notes |
|---|---|---|---|
| PostgreSQL | pgx |
postgres, pg, pgsql, postgresql, px |
github.com/jackc/pgx/v5/stdlib |
| MySQL | mysql |
my, maria, aurora, mariadb, percona |
github.com/go-sql-driver/mysql |
| Microsoft SQL Server | sqlserver |
ms, mssql, azuresql |
github.com/microsoft/go-mssqldb |
| Oracle Database | oracle |
or, ora, oci, oci8, odpi, odpi-c |
github.com/xo/oracle |
| SQLite3 | sqlite3 |
sq, sqlite, file |
github.com/mattn/go-sqlite3 † § |
| DuckDB | duckdb |
dk, ddb, duck, file |
github.com/duckdb/duckdb-go/v2 † § |
| Alibaba MaxCompute | maxcompute |
mc |
github.com/xo/dbimp/maxcompute ¶ |
| Alibaba Tablestore | tablestore |
ot, ots |
github.com/xo/dbimp/tablestore ¶ |
| Amazon Athena | athena |
s3, aws, awsathena |
github.com/xo/dbimp/athena ¶ |
| Amazon Redshift | redshift |
rs |
github.com/jackc/pgx/v5/stdlib ¶ |
| Apache Avatica | avatica |
av, phoenix |
github.com/xo/dbimp/avatica |
| Apache Drill | drill |
dl |
github.com/xo/dbimp/drill |
| Apache Druid | druid |
dr |
github.com/xo/dbimp/druid |
| Apache Hive | hive |
hi, hive2 |
github.com/beltran/gohive/v2 |
| Apache Impala | impala |
im |
github.com/sclgo/impala-go |
| Apache Pinot | pinot |
pi |
github.com/xo/dbimp/pinot |
| Apache Solr | solr |
so |
github.com/xo/dbimp/solr |
| ArangoDB | arangodb |
ar, arango |
github.com/xo/dbimp/arangodb |
| Azure Cosmos DB | cosmos |
cm |
github.com/xo/dbimp/cosmos ¶ |
| Cassandra | cassandra |
ca, cql, scy, cass, scylla, datastax |
github.com/xo/cassandra |
| ChaiSQL | chai |
ci, genji, chaisql |
github.com/chaisql/chai § |
| ClickHouse | clickhouse |
ch |
github.com/xo/dbimp/clickhouse |
| CockroachDB | cockroachdb |
cr, cdb, crdb, cockroach |
github.com/jackc/pgx/v5/stdlib |
| Couchbase | couchbase |
n1, n1ql |
github.com/xo/dbimp/couchbase |
| CrateDB | cratedb |
ct, crate |
github.com/jackc/pgx/v5/stdlib |
| CSVQ | csvq |
cs, csv, tsv, json |
github.com/mithrandie/csvq-driver § |
| Databend | databend |
dd, bend |
github.com/xo/dbimp/databend |
| Databricks | databricks |
br, brick, bricks, databrick |
github.com/xo/dbimp/databricks ¶ |
| DynamoDB | dynamodb |
dy, dyn, dynamo |
github.com/xo/dbimp/dynamodb |
| Elasticsearch | elasticsearch |
es, elastic |
github.com/xo/dbimp/elasticsearch |
| Exasol | exasol |
ex, exa |
github.com/xo/dbimp/exasol |
| Firebird | firebird |
fb, firebirdsql |
github.com/nakagami/firebirdsql |
| FlightSQL | flightsql |
fl, flight |
github.com/apache/arrow-go/v18/arrow/flight/flightsql/driver |
| Google BigQuery | bigquery |
bq |
github.com/xo/dbimp/bigquery ¶ |
| Google Spanner | spanner |
sp |
github.com/xo/dbimp/spanner ¶ |
| InfluxDB | influxdb |
in, influx |
github.com/xo/dbimp/influxdb |
| InfluxDB InfluxQL | influxql |
iq |
github.com/xo/dbimp/influxdb |
| libSQL | libsql |
ls, turso |
github.com/xo/dbimp/libsql |
| ModernC SQLite3 | moderncsqlite |
mq, modernsqlite |
modernc.org/sqlite § |
| Neo4j | neo4j |
nj, neo, n4j |
github.com/xo/dbimp/neo4j |
| ODBC | odbc |
od |
github.com/xo/odbc |
| OpenSearch | opensearch |
os, open |
github.com/xo/dbimp/opensearch |
| PostgreSQL lib/pq | libpq |
pq |
github.com/lib/pq |
| Presto | presto |
pr, prestodb |
github.com/xo/dbimp/trino |
| QuestDB | questdb |
qs |
github.com/jackc/pgx/v5/stdlib |
| rqlite | rqlite |
rq |
github.com/xo/dbimp/rqlite |
| SAP HANA | saphana |
sa, sap, hana, hdb |
github.com/SAP/go-hdb/driver |
| SingleStore MemSQL | memsql |
me |
github.com/go-sql-driver/mysql |
| Snowflake | snowflake |
sf |
github.com/xo/dbimp/snowflake ¶ |
| SurrealDB | surrealdb |
sr, sur, surreal |
github.com/xo/dbimp/surrealdb |
| TiDB | tidb |
ti |
github.com/go-sql-driver/mysql |
| Trino | trino |
tr |
github.com/xo/dbimp/trino |
| Vertica | vertica |
ve |
github.com/vertica/vertica-sql-go |
| Vitess Database | vitess |
vt |
github.com/go-sql-driver/mysql |
| VoltDB | voltdb |
vo, vdb, volt |
github.com/VoltDB/voltdb-client-go/voltdbclient |
| YDB | ydb |
yd |
github.com/ydb-platform/ydb-go-sdk/v3 |
| NO DRIVERS | no_drivers |
leave out every driver that is not named by its tag | |
| NO <TAG> | no_<tag> |
leave out the driver with <tag> |
† Requires CGO
§ Embedded, with no server to run
¶ Hosted service, with no server you can run
Any of the protocol schemes/aliases above can be used in conjunction when
connecting to a database via the command-line or with the \connect and
\copy commands:
# connect to a vitess database:
$ usql vt://user:pass@host:3306/mydatabase
$ usql
(not connected)=> \c vitess://user:pass@host:3306/mydatabase
$ usql
(not connected)=> \copy csvq://. pg://localhost/ 'select * ....' 'myTable'See the section below on connecting to databases for further
details building DSNs/URLs for use with usql.
After installing, usql can be used similarly to the following:
# connect to a postgres database
$ usql postgres://booktest@localhost/booktest
# connect to an oracle database
$ usql oracle://user:pass@host/oracle.sid
# connect to a postgres database and run the commands contained in script.sql
$ usql pg://localhost/ -f script.sqlSupported command-line options:
$ usql --help
usql, the universal command-line interface for SQL databases
Usage:
usql [flags]... [DSN]
Arguments:
DSN database url or connection name
Flags:
-c, --command COMMAND run only single command (SQL or internal) and exit
-f, --file FILE execute commands from file and exit
-w, --no-password[=true|false] never prompt for password
-X, --no-init[=true|false] do not execute initialization scripts (aliases: --no-rc --no-psqlrc --no-usqlrc)
-o, --out FILE output file
-W, --password[=true|false] force password prompt (should happen automatically)
-1, --single-transaction[=true|false] execute as a single transaction (if non-interactive)
-v, --set NAME=VALUE set script variable NAME to VALUE (see \set command, aliases: --var --variable)
-U, --uset NAME=VALUE set setting NAME of usql to VALUE (see \uset command)
-N, --cset NAME=DSN set named connection NAME to DSN (see \cset command)
-P, --pset VAR=ARG set printing option VAR to ARG (see \pset command)
-F, --field-separator FIELD-SEPARATOR field separator for unaligned and CSV output (default "|" and ",")
-R, --record-separator RECORD-SEPARATOR record separator for unaligned and CSV output (default \n)
-T, --table-attr TABLE-ATTR set HTML table tag attributes (e.g., width, border)
-A, --no-align unaligned table output mode
-H, --html HTML table output mode
-t, --tuples-only print rows only
-x, --expanded turn on expanded table output
-z, --field-separator-zero set field separator for unaligned and CSV output to zero byte
-0, --record-separator-zero set record separator for unaligned and CSV output to zero byte
-J, --json JSON output mode
-C, --csv CSV output mode
-G, --vertical vertical output mode
-M, --markdown markdown output mode
-q, --quiet run quietly (no messages, only query output)
--config string config file
-V, --version[=true|false] output version information, then exit
-?, --help[=true|false] show this help, then exitusql opens a database connection by parsing a URL and passing the
resulting connection string to a database driver. Database
connection strings (aka "data source name" or DSNs) have the same parsing rules
as URLs, and can be passed to usql via command-line, or to the \connect,
\c, and \copy commands.
Database connections can be defined with the \cset command
or in the config.yaml configuration file.
Database connection strings look like the following:
driver+transport://user:pass@host/dbname?opt1=a&opt2=b
driver:/path/to/file
/path/to/file
nameWhere the above are:
| Component | Description |
|---|---|
driver |
driver scheme name or scheme alias |
transport |
tcp, udp, unix or driver name (for ODBC and ADODB) |
user |
username |
pass |
password |
host |
hostname |
dbname ± |
database name, instance, or service name/ID |
?opt1=a&... |
additional database driver options (see respective SQL driver for available options) |
/path/to/file |
a path on disk |
name |
a connection name set by \cset or in config.yaml |
usql supports the same driver names and aliases as the dburl
package. Databases have at least one or more aliases. See dburl's
scheme documentation for a list of all supported aliases.
All database drivers have a two character short form that is usually the first
two letters of the database driver. For example, pg for postgres, my for
mysql, ms for sqlserver, or for oracle, or sq for sqlite3.
Driver options are specified as standard URL query options in the form of
?opt1=a&opt2=b. Refer to the relevant database driver's documentation
for available options.
If a URL does not have a driver: scheme, usql will check if it is a path on
disk. If the path exists, usql will attempt to use an appropriate database
driver to open the path.
When the path is a Unix Domain Socket, usql will attempt to open it with the
MySQL driver. When the path is a directory, usql will attempt to open it
using the PostgreSQL driver. And, lastly, when the path is a regular file,
usql will attempt to open the file using the SQLite3 or DuckDB drivers.
As with URLs, most components in the URL are optional and many components can
be left out. usql will attempt connecting using defaults where possible:
# connect to postgres using the local $USER and the unix domain socket in /var/run/postgresql
$ usql pg://See the relevant documentation on database drivers for more information.
When the command line names no DSN, usql opens the DSN in the USQL_DSN
environment variable. A program or a script that holds a password can use it
to keep the password out of the argument list, which every user of the
machine can read:
$ USQL_DSN="pg://app:$PASSWORD@localhost:15432/app" usqlThe variable holds a full DSN or the name of a connection. A DSN on the
command line wins, and usql then does not read the variable. usql removes
the variable from its own environment after it reads it, so that \!, the
pager and the editor do not get the password. \c never reads the variable.
usql has no environment variable for the password alone.
usql opens a database that runs in Kubernetes through a port forward. The
dbfwd package finds the database and its credentials, and runs
kubectl port-forward to it. kubectl must be on the PATH, and it uses the
current context of the kubeconfig, or the one that ?context= names:
# the Service, StatefulSet or pod pg in the namespace prod
$ usql k://pg.prod/app
# the CloudNativePG cluster pg, with another context
$ usql 'k8s+cnpg://pg.prod/app?context=staging'The URL holds no password. dbfwd reads it from the Secret of the operator or
of the pod, so -W does not apply. The banner and \conninfo name what the
forward reached, such as Service pg-rw in context kind-prod, namespace prod, owned by CloudNativePG Cluster pg, and the prompt shows the host from the URL,
such as pg, in place of the local address and port. When the pod restarts, the forward follows it, and
the first statement after that fails as it does after a server restart. When
no pod runs for two minutes, the forward is lost, and \c with no argument
starts it again.
\k lists the databases that usql can reach, with the URL that \c opens:
=> \k -A
List of Kubernetes databases in context kind-prod, every namespace
Namespace | Name | Type | Kind | Operator | URL
-----------+------+----------+---------+------------------+----------------
prod | pg | postgres | Cluster | CloudNativePG | k://pg.prod/
prod | shop | mariadb | MariaDB | mariadb-operator | k://shop.prod/
(2 rows)\k lists the current namespace, -A every namespace, -n NAMESPACE one
namespace, and --context NAME another context. A scope narrows the list,
such as pg*, pg*.prod or cnpg://*, and its k:// is optional. Only *
is a wildcard. \k+ adds the roles, the ready pods, the databases, and where
the password comes from. \k reads no Secret.
On Linux and FreeBSD, if usql is killed, kubectl stops with it. On other
systems, a kubectl port-forward can keep running after usql is killed with
SIGKILL, and it must be stopped by hand.
See dbfwd's URL rules for the types and the parts of the URL, and
its lookup rules for how it finds a database from a name.
The following are example connection strings and additional ways to connect to
databases using usql:
# connect to a postgres database
$ usql pg://user:pass@host/dbname
$ usql pgsql://user:pass@host/dbname
$ usql postgres://user:pass@host:port/dbname
$ usql pg://
$ usql /var/run/postgresql
$ usql pg://user:pass@host/dbname?sslmode=disable # Connect without SSL
# connect to a mysql database
$ usql my://user:pass@host/dbname
$ usql mysql://user:pass@host:port/dbname
$ usql my://
$ usql /var/run/mysqld/mysqld.sock
# connect to a sqlserver database
$ usql sqlserver://user:pass@host/instancename/dbname
$ usql ms://user:pass@host/dbname
$ usql ms://user:pass@host/instancename/dbname
$ usql mssql://user:pass@host:port/dbname
$ usql ms://
# connect to a sqlserver database using Windows domain authentication
$ runas /user:ACME\wiley /netonly "usql mssql://host/dbname/"
# connect to a oracle database
$ usql or://user:pass@host/sid
$ usql oracle://user:pass@host:port/sid
$ usql or://
# connect to a cassandra database
$ usql ca://user:pass@host/keyspace
$ usql cassandra://host/keyspace
$ usql cassandra://host/
$ usql ca://
# connect to an alibaba maxcompute project over https, or over http with tls=false:
$ usql "mc://accessid:accesskey@service.cn-hangzhou.maxcompute.aliyun.com/myproject"
$ usql "mc://accessid:accesskey@host/myproject?region=cn-hangzhou&tls=false"
# connect to an alibaba tablestore instance, where the host
# myinstance.cn-hangzhou becomes myinstance.cn-hangzhou.ots.aliyuncs.com:
$ usql "tablestore://accessid:accesssecret@myinstance.cn-hangzhou/myinstance"
# connect to a sqlite database that exists on disk
$ usql dbname.sqlite3
# Note: when connecting to a SQLite database, if the "driver://" or
# "driver:" scheme/alias is omitted, the file must already exist on disk.
#
# if the file does not yet exist, the URL must incorporate file:, sq:, sqlite3:,
# or any other recognized sqlite3 driver alias to force usql to create a new,
# empty database at the specified path:
$ usql sq://path/to/dbname.sqlite3
$ usql sqlite3://path/to/dbname.sqlite3
$ usql file:/path/to/dbname.sqlite3
# connect to a named connection in config.yaml (see Configuration below for
# where it is on each system)
$ cat $HOME/.config/usql/config.yaml
connections:
my_named_connection: sqlserver://user:pass@localhost/
$ usql my_named_connection
# connect with ODBC driver (needs the ODBC driver manager of the system)
$ cat /etc/odbcinst.ini
[PostgreSQL ANSI]
Description=PostgreSQL ODBC driver (ANSI version)
Driver=psqlodbca.so
Setup=libodbcpsqlS.so
Debug=0
CommLog=1
UsageCount=1
# connect to a postgres database using the odbc config above
$ usql odbc+PostgreSQL+ANSI://user:pass@localhost/dbname?TraceFile=/path/to/trace.logSee the section on connection variables for information on defining connection names.
The interactive interpreter reads queries and backslash meta (\) commands,
sending the query to the connected database:
$ usql sqlserver://sa:pass@localhost
Connected with driver sqlserver (Microsoft SQL Server 2025 17.0.5005.3, RTM-CU9, Enterprise Developer Edition (64-bit))
Type "help" for help.
ms:sa@localhost/master=> select * from authors;
author_id | name
-----------+--------------
1 | Isaac Asimov
2 | Stephen King
(2 rows)
ms:sa@localhost/master=> select title from books
ms:sa@localhost/master-> where author_id = 2
ms:sa@localhost/master-> \p
select title from books
where author_id = 2
ms:sa@localhost/master-> \g
title
--------
Carrie
Cujo
(2 rows)
ms:sa@localhost/master=>A command takes one or more parameters. A parameter can be quoted with either
' or ", and can also be backticked.
usql reads input as psql does, on every database:
- A statement ends at a
;that is outside a string, a quoted name and a comment, or at a meta command such as\g. - Write
\;for a;that must not end the statement.usqlsends it as;. - The body of a stored program between
BEGINandEND, and on Oracle an anonymous block, stays in one statement, so its;need no escape. Inside a PL/SQL package, or in the declarations of a unit before itsBEGIN, write each;as\;. - A line with only
/and SQL Server'sGOare not separators. They are text of the statement, as inpsql. - Input that is not typed, from
-c,-f, a pipe or\i, runs a last statement that has no;. \if,\elif,\elseand\endifchoose the lines that run, as inpsql. A branch that does not run sends no statement, runs no other meta command and replaces no variable, and the prompt's%Rshows@there.
The interactive interpreter edits lines with rline, which reads
~/.inputrc (or the file that INPUTRC names) as GNU Readline does. For
example, set editing-mode vi turns on vi mode, and
"\e[A": history-search-backward makes Up search the history for entries
that start with what is typed. Settings inside $if usql ... $endif apply
only to usql.
usql supports interleaved backslash (\) meta commands to modify or alter
the way that usql interprets queries, formats its output, and changes the
resulting interactive flow.
(not connected)=> \c postgres://user:pass@localhost
pg:user@localhost=> select * from my_table \GAvailable backslash meta commands can be displayed with \?:
$ usql
Type "help" for help.
(not connected)=> \?
General
\q quit usql
\copyright show usage and distribution terms for usql
\drivers show database drivers available to usql
Help
\? [commands] show help on usql's meta (backslash) commands
\? options show help on usql command-line options
\? variables show help on special usql variables
Connection
\c DSN or \c NAME connect to dsn or named database connection
\c DRIVER PARAMS... connect to database with driver and parameters
\Z close (disconnect) database connection
\password [USER] change password for user
\conninfo [-password] display information about the current database connection,
with the password when -password is given
\k[+] [OPTIONS] [SCOPE] list databases in Kubernetes, with the URL for \c (OPTIONS:
-A, -n NAMESPACE, --context NAME)
Query Execute
\g [(OPTIONS)] [FILE] or ; execute query (and send results to file or |pipe)
\G [(OPTIONS)] [FILE] as \g, but forces vertical output mode
\gx [(OPTIONS)] [FILE] as \g, but forces expanded output mode
\gexec execute query and execute each value of the result
\gset [PREFIX] execute query and store results in usql variables
\bind [PARAM]... set query parameters
\timing [on|off] toggle timing of commands
Query View
\crosstab [(OPTIONS)] [COLUMNS] execute query and display results in crosstab
\chart CHART [(OPTIONS)] execute query and display results as a chart
\watch [(OPTIONS)] [INTERVAL] execute query every specified interval
Query Buffer
\e [-raw|-exec] [FILE] [LINE] edit the query buffer, raw (non-interpolated) buffer, the
exec buffer, or a file with external editor
\p [-raw|-exec] show the contents of the query buffer, the raw
(non-interpolated) buffer or the exec buffer
\w [-raw|-exec] FILE write the contents of the query buffer, raw
(non-interpolated) buffer, or exec buffer to file
\r reset (clear) the query buffer
\ef [FUNCNAME [LINE]] edit function definition with external editor
\ev [VIEWNAME [LINE]] edit view definition with external editor
Informational
\d[S+] [NAME] list tables, views, and sequences or describe table, view,
sequence, or index
\da[S+] [PATTERN] list aggregates
\dA[+] [PATTERN] list access methods
\dAc[+] [AMPTRN [PATTERN]] list operator classes
\dAf[+] [AMPTRN [PATTERN]] list operator families
\dAo[+] [AMPTRN [PATTERN]] list operators of operator families
\dAp[+] [AMPTRN [PATTERN]] list support functions of operator families
\db[+] [PATTERN] list tablespaces
\dc[S+] [PATTERN] list conversions
\dconfig[+] [PATTERN] list configuration parameters
\dC[+] [PATTERN] list casts
\dd[S] [PATTERN] show object descriptions not displayed elsewhere
\dD[S+] [PATTERN] list domains
\ddp [PATTERN] list default privileges
\dE[S+] [PATTERN] list foreign tables
\des[+] [PATTERN] list foreign servers
\det[+] [PATTERN] list foreign tables and their servers
\deu[+] [PATTERN] list user mappings
\dew[+] [PATTERN] list foreign-data wrappers
\df[anptw][S+] [PATTERN] list [only agg/normal/procedure/trigger/window] functions
\dF[+] [PATTERN] list text search configurations
\dFd[+] [PATTERN] list text search dictionaries
\dFp[+] [PATTERN] list text search parsers
\dFt[+] [PATTERN] list text search templates
\dg[S+] [PATTERN] list roles
\di[S+] [PATTERN] list indexes
\dl[+] list large objects, same as \lo_list
\dL[S+] [PATTERN] list procedural languages
\dm[S+] [PATTERN] list materialized views
\dn[S+] [PATTERN] list schemas
\do[S+] [PATTERN] list operators
\dO[S+] [PATTERN] list collations
\dp[S] [PATTERN] list table, view, and sequence access privileges
\dP[itn+] [PATTERN] list [only index/table] partitioned relations [n=nested]
\drds [ROLEPTRN [DBPTRN]] list per-database role settings
\drg[S] [PATTERN] list role grants
\dRp[+] [PATTERN] list replication publications
\dRs[+] [PATTERN] list replication subscriptions
\ds[S+] [PATTERN] list sequences
\dt[S+] [PATTERN] list tables
\dT[S+] [PATTERN] list data types
\du[S+] [PATTERN] list roles
\dv[S+] [PATTERN] list views
\dx[+] [PATTERN] list extensions
\dX [PATTERN] list extended statistics
\dy[+] [PATTERN] list event triggers
\l[+] [PATTERN] list databases
\z[S] [PATTERN] same as \dp
\sf[+] FUNCNAME show a function's definition
\sv[+] VIEWNAME show a view's definition
\ss[+] TABLE [k] show stats for the columns of a table
Variables
\set [NAME [VALUE]] set script variable, or show all script variables if no
parameters
\uset [NAME [VALUE]] set a setting of usql, show it if there is no value, or
show all settings if no parameters
\unset NAME unset (delete) script variable
\pset [NAME [VALUE]] set table print formatting option, or show all print
formatting options if no parameters
\cset [NAME [URL]] set named connection, or show all named connections if no
parameters
\cset NAME DRIVER PARAMS... set named connection for driver and parameters
\prompt [-TYPE] VAR [PROMPT] prompt user to set application variable
Input/Output
\echo [-n] [MESSAGE]... write message to standard output (-n for no newline)
\qecho [-n] [MESSAGE]... write message to \o output stream (-n for no newline)
\warn [-n] [MESSAGE]... write message to standard error (-n for no newline)
\o [FILE] send all query results to file or |pipe
\copy SRC DST QUERY TABLE copy results of query from source database into table on
destination database
\copy SRC DST QUERY TABLE(A,...) copy results of query from source database into table's
columns on destination database
Control/Conditional
\i FILE execute commands from file
\ir FILE as \i, but relative to location of current script
\if EXPR begin conditional block
\elif EXPR alternative within current conditional block
\else final alternative within current conditional block
\endif end conditional block
Transaction
\begin [-read-only [ISOLATION]] begin transaction, with optional isolation level
\commit commit current transaction
\rollback rollback (abort) current transaction
Operating System/Environment
\! [COMMAND] execute command in shell or start interactive shell
\cd [DIR] change the current working directory
\getenv VARNAME ENVVAR fetch environment variable
\setenv NAME [VALUE] set or unset environment variable
(not connected)=>Parameters passed to commands can be backticked.
An overview of usql's features, functionality, and compatibility with psql:
- Configuration
- Variables
- Backticks
- Copying Between Databases
- Syntax Highlighting
- Time Formatting
- Context Completion
- Host Connection Information
- Startup Script
- History
The usql project's goal is to support as much of psql's core features and
functionality, and aims to be as compatible as possible - contributions are
always appreciated!
During its initialization phase, usql reads a standard YAML configuration
file config.yaml. It reads the first of these:
- The file that
--confignames. - The file that the
USQL_CONFIGenvironment variable names. usql/config.yamlin the configuration directory of the system:%AppData%/usql/config.yamlon Windows,$HOME/Library/Application Support/usql/config.yamlon macOS, and$XDG_CONFIG_HOME/usql/config.yamlon Linux and other Unix systems, which is$HOME/.config/usql/config.yamlwhenXDG_CONFIG_HOMEis not set. macOS does not readXDG_CONFIG_HOME. SetUSQL_CONFIGto use another file there.
Named connection DSNs can be defined under connections: as a string
or as a map:
connections:
my_couchbase_conn: couchbase://Administrator:P4ssw0rd@localhost
my_clickhouse_conn: clickhouse://clickhouse:P4ssw0rd@localhost
my_oracle_conn:
protocol: oracle
username: system
password: P4ssw0rd
hostname: localhost
port: 1521
database: freeDefined connections: can be used on the command-line with \connect, \c,
\copy, and other commands:
$ usql my_oracle_conn
Connected with driver oracle (Oracle Database 23.0.0.0.0)
Type "help" for help.
or:system@localhost/free=>Please see _samples/config.yaml for an overview of
available configuration options.
usql has script variables, connection
variables, display formatting variables, and settings
of its own. They are set with \set, \cset, \pset and \uset
respectively, and \set is only for scripts: a setting such as pager is not
a variable, and \set pager less is an error that says to use \uset.
Script variables are managed with the \set and \unset commands:
(not connected)=> \unset FOO
(not connected)=> \set FOO bar
(not connected)=>Script variables can be displayed with \set:
(not connected)=> \set
FOO = 'bar'
(not connected)=>When a script variable NAME has been \set, then :NAME, :'NAME', and
:"NAME" will be interpolated into the query buffer:
ms:sa@localhost/master=> \set FOO 'Stephen King'
ms:sa@localhost/master=> select * from authors where name = :'FOO';
author_id | name
-----------+--------------
2 | Stephen King
(1 row)
ms:sa@localhost/master=>Where a runtime variable is used as :'NAME' or :"NAME" the interpolated
value will be quoted using ' or " respectively:
ms:sa@localhost/master=> \set TBLNAME authors
ms:sa@localhost/master=> \set COLNAME name
ms:sa@localhost/master=> \set FOO 'Isaac Asimov'
ms:sa@localhost/master=> select * from :TBLNAME where :"COLNAME" = :'FOO'
ms:sa@localhost/master->The query buffer and interpolated values can be displayed with \p and
\print, or the raw query buffer can be displayed with \raw:
ms:sa@localhost/master=> select * from :TBLNAME where :"COLNAME" = :'FOO'
ms:sa@localhost/master-> \p
select * from authors where "name" = 'Isaac Asimov'
ms:sa@localhost/master-> \raw
select * from :TBLNAME where :"COLNAME" = :'FOO'
ms:sa@localhost/master->Note
Variables contained within other strings will not be interpolated:
ms:sa@localhost/master=> select ':FOO' as foo;
foo
------
:FOO
(1 row)
ms:sa@localhost/master=> \p
select ':FOO' as foo;
ms:sa@localhost/master=>Connection variables work similarly to runtime variables, and are managed with
\cset. Connection variables can be used with the \c, \connect, \copy,
or other commands:
(not connected)=> \cset my_conn sqlserver://sa:pass@localhost
(not connected)=> \c my_conn
Connected with driver sqlserver (Microsoft SQL Server 2025 17.0.5005.3, RTM-CU9, Enterprise Developer Edition (64-bit))
ms:sa@localhost/master=>Connection variables are not interpolated into queries. See the configuration section for information on defining persistent connection variables.
Connection variables can be displayed with \cset:
(not connected)=> \cset
my_conn = 'postgres://user:pass@localhost'
(not connected)=>Display formatting variables can be set using \pset and other
commands:
(not connected)=> \pset time Kitchen
Time display is "Kitchen" ("3:04PM").
(not connected)=> \a
Output format is unaligned.
(not connected)=>Display formatting variables can be displayed with \pset:
(not connected)=> \pset
border 1
columns 0
csv_fieldsep ","
expanded off
fieldsep "|"
fieldsep_zero off
footer on
format aligned
header_align center
json_indent 0
linestyle ascii
locale C
null ""
numericlocale off
pager off
pager_min_lines 0
recordsep "\n"
recordsep_zero off
tableattr
time Kitchen
timezone
title
tuples_only off
unicode_border_linestyle single
unicode_column_linestyle single
unicode_header_linestyle single
(not connected)=>The settings of usql, such as the pager, the editor, the prompts and
on_error_stop, are managed with the \uset command, which works as
\pset does. Without arguments it shows every setting, with a name it shows
that setting, and with a name and a value it sets it. The value is read as the
other meta commands read an argument: it can be quoted, :name is interpolated
and a backtick runs a command.
(not connected)=> \uset pager "less -R"
pager is "less -R"
(not connected)=> \uset on_error_stop on
on_error_stop is on
(not connected)=> \uset
echo_hidden off
editor ""
encoding utf-8
fetch_count 0
on_error_stop on
pager "less -R"
prompt1 "%S%N%m%/%R%# "
prompt2 "%S%N%m%/%R%# "
quiet off
show_host_information true
sslmode retry
syntax_hl true
syntax_hl_format terminal256
syntax_hl_override_bg true
syntax_hl_style monokai
term_graphics
(not connected)=>A setting can also be given on the command line with --uset NAME=VALUE, or
-U NAME=VALUE, and -q is --uset quiet=on. The environment variables
USQL_PAGER, PAGER, USQL_EDITOR, EDITOR, VISUAL, USQL_SSLMODE,
USQL_SHOW_HOST_INFORMATION and USQL_TERM_GRAPHICS give the first value of
their settings.
A script read with -f, \i, \ir, init.sql or from a pipe is UTF-8 unless
it starts with the byte order mark of UTF-16 or UTF-32, as a file that Windows
Notepad or PowerShell saved can. For a script in another encoding, set
encoding to its name in the WHATWG Encoding Standard, such
as windows-1252, shift_jis, euc-kr or gb18030:
$ usql --uset encoding=windows-1252 -f legacy.sql pg://A file takes the setting when it is opened, and a pipe when it is first read. A
script that is not valid UTF-8 in its encoding stops usql with an error that
names the file and the line.
Use the \? variables command to display help information and to
list the variables and the settings recognized by usql:
(not connected)=> \? variablesBackslash (\) meta commands support backticks on parameters:
(not connected)=> \echo Welcome `echo $USER` -- 'running on:' "(" `uname -s` ")"
Welcome user -- running on: ( Linux )
(not connected)=>Backticked parameters will be passed to the user's SHELL, exactly as written,
and can be combined with \set:
(not connected)=> \set MYVAR `uname -s`
(not connected)=> \set
MYVAR = 'Linux'
(not connected)=> \echo :MYVAR
Linux
(not connected)=>usql provides a \copy command that reads data from a source database DSN
and writes to a destination database DSN:
(not connected)=> \cset PGDSN postgres://user:pass@localhost
(not connected)=> \cset MYDSN mysql://user:pass@localhost
(not connected)=> \copy PGDSN MYDSN 'select book_id, author_id from books' 'books(id, author_id)'As demonstrated above, the \copy command does not require being connected to
a database, and will not modify or change the current open database connection
or state.
Any valid URL or DSN name maybe used for the source and destination database:
(not connected)=> \cset MYDSN mysql://user:pass@localhost
(not connected)=> \copy postgres://user:pass@localhost MYDSN 'select book_id, author_id from books' 'books(id, author_id)'Note
usql's\copyis distinct from and does not function likepsql's\copy.
The \copy command has two parameter forms:
\copy SRC DST QUERY TABLE
\copy SRC DST QUERY TABLE(COL1, COL2, ..., COLN)Where:
SRC- is the source database URL to connect to, and where theQUERYwill be executedDST- is the destination database URL to connect to, and where the destinationTABLEresidesQUERY- is the query to execute on theSRCconnection, the results of which will be copied toTABLETABLE- is the destination table name, followed by an optional SQL-like column list of the form(COL1, COL2, ..., COLN)(COL1, COL2, ..., COLN)- a list of the destination column names, 1-to-N
The usual rules for variables, interpolation, and quoting apply to
\copy's parameters.
QUERY and TABLE must be quoted when containing spaces:
$ usql
(not connected)=> echo :SOURCE_DSN :DESTINATION_DSN
pg://postgres:P4ssw0rd@localhost/ mysql://localhost
(not connected)=> \copy :SOURCE_DSN :DESTINATION_DSN 'select * from mySourceTable' 'myDestination(colA, colB)'
COPY 2The QUERY must return the same number of columns as defined by
the TABLE expression:
$ usql
(not connected)=> \copy csvq:. sq:test.db 'select * from authors' authors
error: failed to prepare insert query: 2 values for 1 columns
(not connected)=> \copy csvq:. sq:test.db 'select name from authors' authors(name)
COPY 2The \copy command does not attempt to perform any kind of datatype
conversion.
If a QUERY returns columns with different datatypes than expected by the
TABLE's column, the QUERY can use the source database's conversion/casting
functionality to cast columns to a datatype that will work for TABLE's
columns:
$ usql
(not connected)=> \copy postgres://user:pass@localhost mysql://user:pass@localhost 'SELECT uuid_column::TEXT FROM myPgTable' myMyTable
COPY 1The \copy command is capable of importing data from CSV's (or any other
database!) using the csvq driver:
$ cat authors.csv
author_id,name
1,Isaac Asimov
2,Stephen King
$ cat books.csv
book_id,author_id,title
1,1,I Robot
2,2,Carrie
3,2,Cujo
$ usql
Type "help" for help.
(not connected)=> -- setting variables to make connections easier
(not connected)=> \set SOURCE_DSN csvq://.
(not connected)=> \set DESTINATION_DSN sqlite3:booktest.db
(not connected)=> -- connecting to the destination and creating the schema
(not connected)=> \c :DESTINATION_DSN
Connected with driver sqlite3 (SQLite 3.54.1)
sq:booktest.db=> create table authors (author_id integer, name text);
CREATE TABLE
sq:booktest.db=> create table books (book_id integer not null primary key autoincrement, author_id integer, title text);
CREATE TABLE
sq:booktest.db=> -- adding an extra row to books prior to copying
sq:booktest.db=> insert into books (author_id, title) values (1, 'Foundation');
INSERT 1
sq:booktest.db=> -- disconnecting to demonstrate that \copy opens new database connections
sq:booktest.db=> \disconnect
(not connected)=> -- copying data from SOURCE -> DESTINATION
(not connected)=> \copy :SOURCE_DSN :DESTINATION_DSN 'select * from authors' authors
COPY 2
(not connected)=> \copy :SOURCE_DSN :DESTINATION_DSN 'select author_id, title from books' 'books(author_id, title)'
COPY 3
(not connected)=> \c :DESTINATION_DSN
Connected with driver sqlite3 (SQLite 3.54.1)
sq:booktest.db=> select * from authors;
author_id | name
-----------+--------------
1 | Isaac Asimov
2 | Stephen King
(2 rows)
sq:booktest.db=> select * from books;
book_id | author_id | title
---------+-----------+------------
1 | 1 | Foundation
2 | 1 | I Robot
3 | 2 | Carrie
4 | 2 | Cujo
(4 rows)
sq:booktest.db=>Note
When importing large datasets (> 1GiB) from one database to another, it is better to use a database's native clients and tools.
The \copy command (and all usql commands) works with variables.
When scripting, or when needing to perform multiple \copy operations from/to
multiple sources/destinations, the best practice is to \set connection
variables either in a script or in the init.sql startup script.
Similarly, passwords can be kept out of scripts by defining named
connections in the config.yaml file.
For example:
$ cat $HOME/.config/usql/config.yaml
connections:
pglocal: postgres://postgres:P4ssw0rd@localhost:49153?sslmode=disable
orlocal: oracle://system:P4ssw0rd@localhost:1521/orasid
$ usql
Type "help" for help.
(not connected)=> \copy pglocal orlocal 'select staff_id, first_name from staff' 'staff(staff_id, first_name)'
COPY 18Interactive input is highlighted as you type it. usql parses the input with
the grammar of transit, and the SQL of each statement with the grammar
of the dialect of the connection. The colors come from a style of
transit, which has the styles of Chroma. The settings that control
highlighting are:
| Setting | Default | Values | Description |
|---|---|---|---|
syntax_hl |
true |
true or false |
turns highlighting on and off |
syntax_hl_format |
dependent on terminal support | noop, terminal, terminal256, terminal16m |
the number of colors: none, 16, 256 or 24 bits |
syntax_hl_override_bg |
true |
true or false |
keeps the background of the terminal, and not the style's |
syntax_hl_style |
monokai |
style name | the name of a style |
They are set with \uset. A terminal with no color, or a NO_COLOR variable,
turns highlighting off by default:
$ usql
Type "help" for help.
(not connected)=> \uset syntax_hl_style dracula
syntax_hl_style is dracula
(not connected)=> \uset syntax_hl off
syntax_hl is false
(not connected)=>When using the interactive shell, context completion is available in usql by
hitting the <Tab> key. For example, hitting <Tab> can complete some parts
of SELECT queries on a SQL Server database:
$ usql sqlserver://sa:pass@localhost
Connected with driver sqlserver (Microsoft SQL Server 2025 17.0.5005.3, RTM-CU9, Enterprise Developer Edition (64-bit))
Type "help" for help.
ms:sa@localhost/master=> select * f
1 from
2 fetch
3 full outer joinOr, for example completing backslash commands while connected to a database:
$ usql sqlserver://sa:pass@localhost
Connected with driver sqlserver (Microsoft SQL Server 2025 17.0.5005.3, RTM-CU9, Enterprise Developer Edition (64-bit))
Type "help" for help.
ms:sa@localhost/master=> \g
1 \g 4 \gset
2 \go 5 \gexec
3 \gx 6 \getenvNot all commands, contexts, or databases support completion. To help improve it, see the section below on contributing.
Command completion can be canceled with <Control-C>.
Some databases support time/date columns that support formatting. By
default, usql formats time/date columns as RFC3339Nano, and can be
set using \pset time FORMAT:
$ usql sqlserver://sa:pass@localhost
Connected with driver sqlserver (Microsoft SQL Server 2025 17.0.5005.3, RTM-CU9, Enterprise Developer Edition (64-bit))
Type "help" for help.
ms:sa@localhost/master=> \pset time
Time display is "RFC3339Nano" ("2006-01-02T15:04:05.999999999Z07:00").
ms:sa@localhost/master=> select cast('2026-10-31 09:41:27.123456' as datetime2) as stamp;
stamp
-----------------------------
2026-10-31T09:41:27.123456Z
(1 row)
ms:sa@localhost/master=> \pset time Kitchen
Time display is "Kitchen" ("3:04PM").
ms:sa@localhost/master=> select cast('2026-10-31 09:41:27.123456' as datetime2) as stamp;
stamp
--------
9:41AM
(1 row)
ms:sa@localhost/master=>usql's time format supports any Go supported time format, or can
be any standard Go const name, such as Kitchen above. See below for an
overview of the available time constants.
The following are the time constant names available in usql, corresponding
time format value, and example display output:
| Constant | Format | Display ↓ |
|---|---|---|
| ANSIC | Mon Jan _2 15:04:05 2006 |
Wed Aug 3 20:12:48 2022 |
| UnixDate | Mon Jan _2 15:04:05 MST 2006 |
Wed Aug 3 20:12:48 UTC 2022 |
| RubyDate | Mon Jan 02 15:04:05 -0700 2006 |
Wed Aug 03 20:12:48 +0000 2022 |
| RFC822 | 02 Jan 06 15:04 MST |
03 Aug 22 20:12 UTC |
| RFC822Z | 02 Jan 06 15:04 -0700 |
03 Aug 22 20:12 +0000 |
| RFC850 | Monday, 02-Jan-06 15:04:05 MST |
Wednesday, 03-Aug-22 20:12:48 UTC |
| RFC1123 | Mon, 02 Jan 2006 15:04:05 MST |
Wed, 03 Aug 2022 20:12:48 UTC |
| RFC1123Z | Mon, 02 Jan 2006 15:04:05 -0700 |
Wed, 03 Aug 2022 20:12:48 +0000 |
| RFC3339 | 2006-01-02T15:04:05Z07:00 |
2022-08-03T20:12:48Z |
| RFC3339Nano | 2006-01-02T15:04:05.999999999Z07:00 |
2022-08-03T20:12:48.693257Z |
| Kitchen | 3:04PM |
8:12PM |
| Stamp | Jan _2 15:04:05 |
Aug 3 20:12:48 |
| StampMilli | Jan _2 15:04:05.000 |
Aug 3 20:12:48.693 |
| StampMicro | Jan _2 15:04:05.000000 |
Aug 3 20:12:48.693257 |
| StampNano | Jan _2 15:04:05.000000000 |
Aug 3 20:12:48.693257000 |
↓ Generated using timestamp 2022-08-03T20:12:48.693257Z
By default, usql displays connection information when it connects to a
database. Some databases and connections do not work with this. Set the
environment variable USQL_SHOW_HOST_INFORMATION to false to turn it off:
$ export USQL_SHOW_HOST_INFORMATION=false
$ usql sqlserver://sa:pass@localhost
Type "help" for help.
ms:sa@localhost/master=>show_host_information is a setting of usql, and is set with
\uset. Additionally, it can be passed via the command-line using --uset:
$ usql --uset show_host_information=false sqlserver://sa:pass@localhost
Type "help" for help.
ms:sa@localhost/master=> \uset show_host_information true
show_host_information is true
ms:sa@localhost/master=> \connect sqlserver://sa:pass@localhost
Connected with driver sqlserver (Microsoft SQL Server 2025 17.0.5005.3, RTM-CU9, Enterprise Developer Edition (64-bit))
ms:sa@localhost/master=>usql supports terminal graphics for Kitty, iTerm,
and Sixel enabled terminals using the github.com/kenshaw/rasterm package.
Terminal graphics are only available when using the interactive shell.
usql will attempt to detect when terminal graphics support is available using
the USQL_TERM_GRAPHICS, TERM_GRAPHICS and other environment variables
unique to various terminals.
When support is available, the logo will be displayed at the start of an interactive session:
The \chart command can be used to display a chart
directly in the terminal:
See the section on the \chart meta command for details.
The renderer runs Apache ECharts in a JavaScript engine and rasterizes the
result with an SVG renderer, which together add about 12 MiB to the binary.
Every build has it, unless its build tags leave it out. The tag no_charts
leaves it out, and so does no_drivers unless the tag charts is also given.
A build without it reports that it has no chart renderer.
Terminal graphics can be forced enabled or disabled by setting the
USQL_TERM_GRAPHICS or the TERM_GRAPHICS environment variable:
# disable
$ USQL_TERM_GRAPHICS=none usql
# force iterm graphics
$ TERM_GRAPHICS=iterm usql| Variable | Default | Values | Description |
|---|---|---|---|
TERM_GRAPHICS |
`` | ``, kitty, `iterm`, `sixel`, `none` |
enables/disables term graphics |
The following terminals have been tested with usql:
-
WezTerm is a cross-platform terminal for Windows, macOS, Linux, and many other platforms that supports iTerm graphics
-
kitty is a terminal for Linux, macOS, and various BSDs that supports Kitty graphics
-
foot is a Wayland terminal for Linux (and other Wayland hosts) that supports Sixel graphics
Additional terminals that support Sixel graphics are catalogued on the Are We Sixel Yet? website.
usql runs the file init.sql in its configuration directory at
startup, as psql runs ~/.psqlrc. It runs after usql opens the connection
named on the command line, and before any -c / --command or -f / --file
flag and before the first prompt:
$XDG_CONFIG_HOME/usql/init.sqlon Linux and other Unix systems, which is$HOME/.config/usql/init.sqlwhenXDG_CONFIG_HOMEis not set.$HOME/Library/Application Support/usql/init.sqlon macOS.%AppData%\usql\init.sqlon Windows.
The USQLRC environment variable names another file. usql reads the file as
it reads a file passed with -f / --file, so it can hold any meta command
and any SQL statement. A statement runs on the connection named on the command
line, and fails with error: not connected when there is none. The file is
commonly used to set variables and settings:
$ cat $HOME/.config/usql/init.sql
\echo WELCOME TO THE JUNGLE `date`
\uset syntax_hl_style paraiso-dark
-- set color prompt (default is prompt is "%S%m%/%R%#" )
\uset prompt1 "\033[32m%S%m%/%R%#\033[0m"
$ usql
WELCOME TO THE JUNGLE Thu Jun 14 02:36:53 WIB 2018
Type "help" for help.
(not connected)=> \uset syntax_hl_style
syntax_hl_style is "paraiso-dark"
(not connected)=>See _samples/init.sql for a sample.
Pass -X or --no-init on the command-line to skip the file:
$ usql --no-init pg://usql no longer reads $HOME/.usqlrc, the init: script of config.yaml or
the $HOME/.usqlpass password file. Move the script to init.sql, and
define named connections in the config.yaml
file in place of the password file.
At a terminal, usql keeps the history of what was typed in the file
history in its state directory:
$XDG_STATE_HOME/usql/historyon Linux and other Unix systems, which is$HOME/.local/state/usql/historywhenXDG_STATE_HOMEis not set.$HOME/Library/Application Support/usql/historyon macOS.%LocalAppData%\usql\historyon Windows.
The USQL_HISTORY environment variable names another file. usql prints a
warning at startup when it cannot read the file, and then does not save the
history. It does not read $HOME/.usql_history.
The following are additional notes and miscellania related to usql:
Release builds include every driver, and are built with
additional SQLite3 build tags (see: build.sh). The 32 bit arm
build leaves out ChaiSQL and DuckDB.
The recommended installation method on macOS is via brew due
to the way library dependencies for the sqlite3 driver are done on macOS. If
the following (or similar) error is encountered when attempting to run usql:
$ usql
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicuuc.68.dylib
Referenced from: /Users/user/.local/bin/usql
Reason: image not found
Abort trap: 6Then missing library dependency can be fixed by installing
icu4c using brew:
$ brew install icu4c
Running `brew update --auto-update`...
==> Downloading ...
...
$ usql
(not connected)=>On Linux, the first query through the SQLite ODBC driver crashes usql in a
build that links both the sqlite3 driver and DuckDB, as a build with every
driver does. The DuckDB bindings export the sqlite3_* functions of the SQLite
that the sqlite3 driver carries. The SQLite ODBC driver then gets some of its
sqlite3_* functions from usql and some from the system SQLite, and the two
copies do not match. The odbc project explains it in full.
If you need the SQLite ODBC driver, build with the tag libsqlite3. The
sqlite3 driver then uses the SQLite of the system, and exports no sqlite3_*
function. Add the tag to a build with every driver, or build with only the
ODBC driver:
# every driver, with the SQLite of the system
$ go install -tags libsqlite3 github.com/xo/usql@main
# only the ODBC driver
$ go install -tags 'no_drivers odbc libsqlite3' github.com/xo/usql@mainThe other ODBC drivers work without the tag. The PostgreSQL Unicode driver was checked against PostgreSQL 18.
The server could not meet the durability that the transaction asked for. By
default a transaction asks for majority, which a single-node server cannot
meet. usql does not change the durability unless you ask it to. Set durability_level=none in the URL for a single-node server,
such as a local development server:
$ usql "couchbase://user:pass@localhost/?durability_level=none"The other values are majority, majorityAndPersistActive and
persistToMajority.
The server ends a transaction after 15 seconds by default, which is too short
for a person typing into one. usql sets txtimeout=30m when the URL does not
set txtimeout. Set it in the URL to choose another value:
$ usql "couchbase://user:pass@localhost/?txtimeout=2m"usql is currently a WIP, and is aiming towards a 1.0 release soon. Report a
bug, ask a question, or propose a feature in GitHub
Discussions. The repository takes no issues and no pull
requests. For technical details, see CONTRIBUTING.md.


