Skip to content

Special commands ​

Special commands run as soon as you press Enter, with no ; needed. Most start with \. On SQLite the dot commands (.tables, .schema, …) work too, and a few MySQL-style words (use, source, status, …) are also understood.

\? lists the commands available on the current database. \? word filters that list.

Reading this page ​

  • Aliases are other names for the same command. Any of them works.
  • [+] means you can add + for more detail: \dt+.
  • [pattern] narrows the list:
    • * and ? are wildcards: \dt user*.
    • schema.name limits it to one schema, and schema.* lists everything in it.
    • Quote a name to match it exactly: \d "MixedCase".
    • On PostgreSQL, unquoted names are folded to lower case.
    • Without a schema, only objects on your search path (PostgreSQL) or in the current database (MySQL) are listed.
  • Databases says where a command is listed in \?. Elsewhere, it prints a short note saying the database doesn't support it.

General ​

CommandAliasesDoes
\? [command]help, \h, \help, .helpList commands, or filter the list
\qquit, exit, \quit, .quit, .exitQuit
\! commandsystemRun a shell command
\echo textPrint text
\e [file] or query \e\editEdit the last query, a given query, or a file in $VISUAL / $EDITOR. The text comes back to the prompt.
\i filesource, \ir, \., .read, \includeRun a file, like -f: SQL, plus special commands on their own lines. Stops at the first error, and a \q in the file quits.
\history [n]Show the last n statements (default 20)
\llm question\aiAsk the configured model to write SQL. See Asking a model for SQL.
\theme [name]List themes, or switch to one
\R [format]prompt, \promptSet the prompt format. With no format, go back to auto.
\refreshrehash, \#, \rehashReload the table and column names used for completion
\tuiOpen the TUI on this connection

Describing the database ​

CommandAliasesDatabasesDoes
\l[+] [pattern]\list, .databasesallList databases. + adds size and more.
\d[+] [pattern]describe, desc, \describeallWithout a pattern, list all tables and views. With one, describe each match: columns, indexes, constraints, foreign keys, referencing tables and triggers. + adds sizes, comments and view definitions.
\dt[+] [pattern].tablesallList tables. (.tables includes views.)
\dv[+] [pattern].viewsallList views
\dm[+] [pattern]PostgreSQLList materialized views
\dE[+] [pattern]PostgreSQLList foreign tables
\di[+] [pattern].indexes, .indicesallList indexes; the pattern matches the index or table name
\ds [pattern]PostgreSQL, MySQLList sequences (on MariaDB, sequence tables)
\df[+] [pattern]allList functions and procedures
\dn [pattern]allList schemas. On SQLite, attached databases.
\du [pattern]\dgPostgreSQL, MySQLList roles or users
\dT [pattern]PostgreSQLList data types
\dx [pattern]PostgreSQL, MySQLList extensions (MySQL: plugins)
\dp [pattern]\zPostgreSQL, MySQLList access privileges
\sf[+] functionPostgreSQL, MySQLShow a function's definition
\sv[+] viewallShow a view's definition
.schema [pattern]\schemaallShow CREATE statements
\sstatus, .status, \statusallConnection and server status: version, user, uptime, encodings, transaction, read-only, TLS
\conninfoallWhere and how you're connected

describe t and desc t describe a table. DESCRIBE SELECT … and DESC t column go to the server as SQL, as MySQL users expect.

Output ​

CommandAliasesDoes
\x [on|off|auto]\expandedVertical output. Without an argument, cycles off → on → auto.
\timing [on|off]\tShow or hide statement timing. On SQLite, .timer on also works.
\T [format]\tableformat, .modeShow or set the output format
\pager [command]pager, \PTurn the pager on, optionally with a command
\nopagernopagerTurn the pager off
tee [-o] file\tee, .outputAlso write every result to a file, appending (-o overwrites; .output always overwrites). .output alone or .output stdout stops.
notee\noteeStop tee
\o [-o] file\once, .onceWrite the next result to a file instead of the screen
\| command\pipe_oncePipe the next result to a shell command
query \clipCopy the query (or the last one) to the clipboard
\export format file queryWrite a query's complete result to a file in any format

Running queries ​

CommandAliasesDatabasesDoes
\watch [sec] [-c] [query] or query \watch [sec]watchallRe-run a query every sec seconds (default 2) until Ctrl+C. -c clears the screen each time. Without a query, watches the last one.
\format [query]allPretty-print a query (or the last one) and put it back at the prompt
\explain [analyze] queryallShow the plan as a tree with costs, rows and, with analyze, actual times
delimiter string\delimiterMySQLChange the statement terminator, e.g. delimiter //. delimiter ; restores it.
\readonly [on|off]allToggle read-only mode
.load path\loadSQLiteLoad a SQLite extension

Favourites ​

CommandAliasesDoes
\f [name [args…]]\nList favourites, or run one
\fs name query\nsSave a favourite. $1…$9, $* and ${name} are placeholders.
\fd name\ndDelete a favourite

See Favourite queries.

Connection ​

CommandAliasesDoes
\c [name | database | url]\connect, use, \u, .openSwitch to a saved connection, another database, or another server. Without an argument, show the current connection.
  • \c prod opens the saved connection prod, with its password command, tunnel and start-up SQL. A saved name wins over a database with the same name.
  • \c other_db switches database on the same server (PostgreSQL reconnects; MySQL runs USE).
  • \c postgres://… connects to a different server.
  • On SQLite, \c file.db or .open file.db opens another file (creating it if needed).
  • use db is not a command on SQLite; there it goes to the server as SQL.

Statement terminators ​

These aren't commands, but they end a statement:

EndingEffect
;Run the statement
\GRun it and show the result vertically
\gRun it (like ;)

Released under the MIT licence.