Skip to content

Meta commands

The meta commands of usql v0.19.13-0.20261129074835-be3acfadfc0c, in the sections of \?. A meta command starts with a backslash. An argument in brackets, such as [PATTERN], can be left out.

A group of letters in brackets after a name adds each combination of its letters. So\d[Sx+] is \d, \dS, \d+, \dS+ and the rest. S shows the objects of the system, xshows the result in expanded mode, and + shows more columns. \? leaves out the aliases, and \? commands lists them.

General

CommandDescription
\qquit usql
\quitalias for \q
\errverboseshow most recent error message at maximum verbosity
\driversshow database drivers available to usql

Help

CommandDescription
\?show help on usql's meta (backslash) commands
\? commandsas \?, but shows all command aliases
\? optionsshow help on usql command-line options
\? variablesshow help on special usql variables
\? stylesshow usql syntax highlighting styles

Connection

CommandDescription
\c DSN or \c NAMEconnect to dsn or named database connection
\c DRIVER PARAMS...connect to database with driver and parameters
\connectalias for \c
\conninfo [-password]display information about the current database connection, with the password when -password is given
\Zclose (disconnect) database connection
\disconnectalias for \Z
\password [USER]change password for user
\passwdalias for \password

Query Execute

CommandDescription
\g [(OPTIONS)] [FILE] or ;execute query (and send results to file or |pipe)
\goalias for \g
\G [(OPTIONS)] [FILE]as \g, but forces vertical output mode
\egoalias for \G
\gx [(OPTIONS)] [FILE]as \g, but forces expanded output mode
\gexecexecute query and execute each value of the result
\gset [PREFIX]execute query and store results in usql variables
\gdescdescribe result of query, without executing it
\bind [PARAM]...set query parameters
\timing [on|off]toggle timing of commands

Query View

CommandDescription
\crosstab [(OPTIONS)] [COLUMNS]execute query and display results in crosstab
\crosstabviewalias for \crosstab
\xtabalias for \crosstab
\chart CHART [(OPTIONS)]execute query and display results as a chart
\watch [(OPTIONS)] [INTERVAL]execute query every specified interval

Query Buffer

CommandDescription
\e [-raw] [FILE] [LINE]edit the query buffer (or file) with external editor (-raw for the non-interpolated buffer)
\editalias for \e
\ef [FUNCNAME [LINE]]edit function definition with external editor
\ev [VIEWNAME [LINE]]edit view definition with external editor
\p [-raw]show the contents of the query buffer (-raw for the non-interpolated buffer)
\printalias for \p
\execalias for \p
\rawas \p, but forces raw mode
\w [-raw] FILEwrite the query buffer to file (-raw for the non-interpolated buffer)
\writealias for \w
\rreset (clear) the query buffer
\resetalias for \r
\s [FILE]display history or save it to file
\hist [COUNT]show the history, or its last COUNT entries
\historyalias for \hist

Informational

(options: S = show system objects, x = expanded mode, + = additional detail)

CommandDescription
\d[Sx+] [NAME]list tables, views, and sequences or describe table, view, sequence, or index
\d[tvmsEi][Sx+]alias for \d[Sx+]
\da[Sx+] [PATTERN]list aggregates
\dA[x+] [PATTERN]list access methods
\dAc[x+] [AMPTRN [PATTERN]]list operator classes
\dAf[x+] [AMPTRN [PATTERN]]list operator families
\dAo[x+] [AMPTRN [PATTERN]]list operators of operator families
\dAp[x+] [AMPTRN [PATTERN]]list support functions of operator families
\db[x+] [PATTERN]list tablespaces
\dc[Sx+] [PATTERN]list conversions
\dconfig[x+] [PATTERN]list configuration parameters
\dC[x+] [PATTERN]list casts
\dd[Sx] [PATTERN]show object descriptions not displayed elsewhere
\dD[Sx+] [PATTERN]list domains
\ddp[x] [PATTERN]list default privileges
\dE[Sx+] [PATTERN]list foreign tables
\des[x+] [PATTERN]list foreign servers
\det[x+] [PATTERN]list foreign tables and their servers
\deu[x+] [PATTERN]list user mappings
\dew[x+] [PATTERN]list foreign-data wrappers
\df[anptw][Sx+] [NAME [TYPES]]list [only agg/normal/procedure/trigger/window] functions
\dF[x+] [PATTERN]list text search configurations
\dFd[x+] [PATTERN]list text search dictionaries
\dFp[x+] [PATTERN]list text search parsers
\dFt[x+] [PATTERN]list text search templates
\dg[Sx+] [PATTERN]list roles
\di[Sx+] [PATTERN]list indexes
\dl[x+]list large objects, same as \lo_list
\dL[Sx+] [PATTERN]list procedural languages
\dm[Sx+] [PATTERN]list materialized views
\dn[Sx+] [PATTERN]list schemas
\do[Sx+] [NAME [TYPES]]list operators
\dO[Sx+] [PATTERN]list collations
\dp[Sx] [PATTERN]list table, view, and sequence access privileges
\dP[itn][x+] [PATTERN]list [only index/table] partitioned relations [n=nested]
\drds[x] [ROLEPTRN [DBPTRN]]list per-database role settings
\drg[Sx] [PATTERN]list role grants
\dRp[x+] [PATTERN]list replication publications
\dRs[x+] [PATTERN]list replication subscriptions
\ds[Sx+] [PATTERN]list sequences
\dt[Sx+] [PATTERN]list tables
\dT[Sx+] [PATTERN]list data types
\du[Sx+] [PATTERN]list roles
\dv[Sx+] [PATTERN]list views
\dx[x+] [PATTERN]list extensions
\dX[x] [PATTERN]list extended statistics
\dy[x+] [PATTERN]list event triggers
\l[x+] [PATTERN]list databases
\list[x+]alias for \l
\lo_list[x+]alias for \dl
\z[Sx] [PATTERN]same as \dp
\sf[+] FUNCNAMEshow a function's definition
\sv[+] VIEWNAMEshow a view's definition
\ss[+] TABLE [k]show stats for the columns of a table
\k[+] [OPTIONS] [SCOPE]list databases in Kubernetes, with the URL for \c (OPTIONS: -A, -n NAMESPACE, --context NAME)
\kube[+]alias for \k

Settings

CommandDescription
\config [OPTIONS] [NAME [VALUE]]set configuration option NAME (SECTION.NAME), or show the settings of usql and print if no parameters (OPTIONS: -all shows every section, -password shows passwords)
\pset [NAME [VALUE]]set table print formatting option, or show all print formatting options if no parameters
\atoggle between unaligned and aligned output mode Deprecated.
\C [TITLE]set table title, or unset if none Deprecated.
\f [SEPARATOR]show or set field separator for unaligned query output Deprecated.
\Htoggle HTML output mode Deprecated.
\htmlalias for \H
\T [ATTRIBUTES]set HTML <table> tag attributes, or unset if none Deprecated.
\t [on|off]show only rows Deprecated.
\x [on|off|auto]toggle expanded output Deprecated.
\uset [NAME [VALUE]]set usql configuration option, or show all usql settings if no parameters
\cset [NAME [URL]]set named connection, or show all named connections if no parameters
\cset NAME DRIVER PARAMS...set named connection for driver and parameters

Input/Output

CommandDescription
\echo [-n] [MESSAGE]...write message to standard output (-n for no newline)
\qecho [-n] [MESSAGE]...write message to \o output stream (-n for no newline)
\warn [-n] [MESSAGE]...write message to standard error (-n for no newline)
\o [FILE]send all query results to file or |pipe
\outalias for \o
\copy SRC DST QUERY TABLEcopy results of query from source database into table on destination database
\copy SRC DST QUERY TABLE(A,...)copy results of query from source database into table's columns on destination database
\dump [OPTIONS] [FILE]write the database as a usql script to the output, a file or |pipe (OPTIONS: -target DRIVER, -schema-only, -data-only, -schema PATTERN, -exclude-schema PATTERN, -table PATTERN, -exclude-table PATTERN, -allow-lossy, -allow-text, -restrict-key KEY)

Control/Conditional

CommandDescription
\set [NAME [VALUE]]set script variable, or show all script variables if no parameters
\unset NAMEunset (delete) script variable
\prompt [-TYPE] VAR [PROMPT]prompt user to set script variable
\i FILEexecute commands from file
\includealias for \i
\ir FILEas \i, but relative to location of current script
\include_relativealias for \ir
\if EXPRbegin conditional block
\elif EXPRalternative within current conditional block
\elsefinal alternative within current conditional block
\endifend conditional block
\restrict RESTRICT_KEYenter restricted mode with provided key
\unrestrict RESTRICT_KEYexit restricted mode if key matches

Transaction

CommandDescription
\begin [-read-only [ISOLATION]]begin transaction, with optional isolation level
\commitcommit current transaction
\rollbackrollback (abort) current transaction
\abortalias for \rollback

Operating System/Environment

CommandDescription
\! [COMMAND]execute command in shell or start interactive shell
\cd [DIR]change the current working directory
\getenv VARNAME ENVVARfetch environment variable
\setenv NAME [VALUE]set or unset environment variable of the commands that usql runs