Skip to content

First steps

This page follows the recording below. It uses a SQLite file, so you need no database server.

Open a SQLite file, list its tables, run a query, and print the result as CSV.

Give usql the database as a URL, or as the path of a file:

Terminal window
usql books.db

usql 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=>.

\dt lists the tables. \d books describes the table books. \? lists every backslash command.

Type SQL and end it with a semicolon. usql runs the statement when you press Enter after the semicolon:

select a.name, count(*) as books
from authors a join books b on b.author_id = a.id
group by a.name order by books desc;

A statement can span lines. The prompt changes to -> until the statement ends.

\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.