Describe a database
The describe commands list what a database holds and describe one object, such as a table. They are the meta commands that start with \d, and \l. They work as they do in psql, on every database that usql has the metadata for. Metadata is the data about the tables, columns and indexes of a database.
List the objects
Section titled “List the objects”| Command | What it lists |
|---|---|
\d |
the tables, the views and the sequences |
\dt |
the tables |
\dv |
the views |
\di |
the indexes, each with its table |
\df |
the functions |
\dn |
the schemas |
\l |
the databases |
Each command takes a pattern, to list only the names that match. * matches any text, and a dot separates the schema from the name:
\dt prod*\dt main.*Describe one object
Section titled “Describe one object”\d with a name describes that object. For a table, it prints the columns, their types, which columns can be NULL, the default values, the indexes and the foreign keys:
\d orders\d describes a view in the same way.
More detail
Section titled “More detail”A letter after the command changes what it prints:
| Letter | What it does |
|---|---|
+ |
prints more columns, such as the description of each object |
S |
lists the objects of the system too, such as built-in functions |
x |
prints the result in expanded mode, one column on each line |
For example, \dt+ lists the tables with more detail, and \dfS lists the built-in functions too.
SQLite and DuckDB
Section titled “SQLite and DuckDB”A SQLite file has one schema, main. \l lists main as its database. SQLite keeps no functions in a database file, so \df lists functions that the SQLite library has, such as those of its extensions.
A DuckDB file can hold more schemas. A table that you make with no schema goes into main. \dn lists the schemas that you made, and main. \dnS adds the schemas of the system, information_schema and pg_catalog. \l lists the database of the file, by the name of the file. \df lists the macros that you made.
On DuckDB, as on PostgreSQL, a pattern with no schema matches only the objects that the search path makes visible. The search path is main unless you change it. So if the file also has a schema other, \dt lists the tables of main only. \dt other.* lists the tables of other, and \dt *.* lists the tables of every schema.
\d with the name of an index prints its columns, their types, the kind of the index and its table:
=> \d orders_product Index "main.orders_product" Column | Type | Key? | Definition------------+---------+------+------------ product_id | INTEGER | yes | product_idart, for table "main.orders"art is the kind of index that DuckDB makes. On SQLite, the kind is btree.
Where the metadata comes from
Section titled “Where the metadata comes from”usql reads the metadata with the library dbmeta. A describe command works only where dbmeta has the metadata for that database. If it does not, usql prints an error and runs nothing:
error: \du not supported by duckdb driverFor example, neither SQLite nor DuckDB has users or roles, so \du does not work on them. \dT, which lists data types, works on DuckDB and not on SQLite.
\? lists every describe command. Most of them are for PostgreSQL and the databases like it.