First steps
This page follows the recording below. It uses a SQLite file, so you need no database server.
Open a database
Section titled “Open a database”Give usql the database as a URL, or as the path of a file:
usql books.dbusql opens a file that exists with the SQLite or DuckDB driver. For a server, give its URL, such as pg://user@localhost/books. Connect to a database explains the URLs.
The prompt starts with the short name of the driver and the database, as in sq:books.db=>.
List the tables
Section titled “List the tables”\dt lists the tables. \d books describes the table books. \? lists every backslash command.
Run a query
Section titled “Run a query”Type SQL and end it with a semicolon. usql runs the statement when you press Enter after the semicolon:
select a.name, count(*) as booksfrom authors a join books b on b.author_id = a.idgroup by a.name order by books desc;A statement can span lines. The prompt changes to -> until the statement ends.
Change the output format
Section titled “Change the output format”\pset format changes how usql prints a result. The formats include aligned, csv, json, html and markdown:
\pset format csv\q closes the connection and leaves usql. Ctrl-D does the same at an empty prompt.