Coming from psql
usql follows PostgreSQL’s psql. If you know psql, you already know most of usql. This page lists what stays the same, what usql adds, and what is missing.
What works as in psql
Section titled “What works as in psql”- A statement ends at a
;, or at a meta command such as\g. A meta command is a command that starts with a backslash. usql reads its input aspsqldoes, on every database. - The prompt shows
=>for a new statement and->while a statement continues on another row. helpshows a short help, andquitorexitleaves usql. Ctrl-C clears the line, and Ctrl-D at an empty prompt leaves usql.- The meta commands have the names and the arguments of
psql. For example,\d,\dt,\x,\pset,\g,\gx,\gset,\gexec,\watch,\e,\i,\o,\timing, and\ifwith\elif,\elseand\endif. \setsets a variable, and:name,:'name'and:"name"put its value into a statement.- A backtick in the argument of a meta command runs a shell command, as in
psql. -cruns one command,-fruns a file, and-Xskips the startup file.
What usql adds
Section titled “What usql adds”- Many databases. usql opens PostgreSQL, MySQL, SQLite, SQL Server, Oracle, DuckDB and many more from a URL.
\copens a database of another kind in the same session. Connect to a database explains the URLs. \copybetween databases. usql’s\copyruns a query on one database and inserts the rows into a table of another database. It does not read or write a file as the\copyofpsqldoes.\dumpwrites a database as a usql script. The script can make the database again, also on a database of another kind.\chartdraws the result of a query as a chart in a terminal that draws images. Your first chart shows how.- Named connections, with
\csetand theconnections:section ofconfig.yaml. - Completion of meta commands, SQL words and names, in a numbered menu.
- Syntax highlighting of what you type, in the grammar of the database.
Settings are not variables
Section titled “Settings are not variables”In psql, \set sets both your own variables and the special variables, such as ON_ERROR_STOP. In usql, \set sets only your own variables. The behavior of usql comes from settings, which \uset sets, and their names are in lower case:
\uset on_error_stop onusql refuses the name of a setting of psql in \set, and names the setting to use:
error: ON_ERROR_STOP is a setting of usql, so it is not a variable: use \uset on_error_stop-v ON_ERROR_STOP=1 on the command line stops usql with the same error. Use -U on_error_stop=on in its place. Configure usql explains the settings.
Options of the command line
Section titled “Options of the command line”Most options have the letters of psql, such as -c, -f, -v, -o, -1, -X, -t and -A. These are different:
-Usets a setting of usql, as in-U on_error_stop=on. Inpsql,-Uis the user name. usql reads the user from the URL.- usql has no
-hand no-p, the host and the port ofpsql. Give a URL.-dtakes a URL or the name of a connection, as the argument does. -D(--dump) writes the database as a usql script. Dump a database shows it.
usql --help lists every option.
Files that usql reads in place of psql’s
Section titled “Files that usql reads in place of psql’s”| psql | usql |
|---|---|
~/.psqlrc |
init.sql in the configuration directory of usql |
~/.psql_history |
history in the state directory of usql |
~/.inputrc |
the same file. A $if usql block applies only to usql |
Configure usql says where these directories are on each system.
What usql does not have
Section titled “What usql does not have”\hand\help. usql has no help for SQL statements.\?lists the meta commands.- The
\copyofpsql, which copies between a table and a file. - The meta commands of the extended query protocol, such as
\parse,\bind_namedand\startpipeline. \lo_importand\lo_export.\encoding. usql reads a script as UTF-8. The settingencodingnames another encoding for a script.
The meta commands page lists every meta command that usql has.