3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "PSQL" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 psql \- PostgreSQL interactive terminal
34 \fBpsql\fR [\fIoption\fR...] [\fIdbname\fR\ [\fIusername\fR]]
38 is a terminal\-based front\-end to
39 PostgreSQL\&. It enables you to type in queries interactively, issue them to
40 PostgreSQL, and see the query results\&. Alternatively, input can be from a file or from command line arguments\&. In addition,
42 provides a number of meta\-commands and various shell\-like features to facilitate writing scripts and automating a wide variety of tasks\&.
49 Print all nonempty input lines to standard output as they are read\&. (This does not apply to lines read interactively\&.) This is equivalent to setting the variable
59 Switches to unaligned output mode\&. (The default output mode is
60 aligned\&.) This is equivalent to
61 \fB\epset format unaligned\fR\&.
66 \fB\-\-echo\-errors\fR
68 Print failed SQL commands to standard error output\&. This is equivalent to setting the variable
74 \fB\-c \fR\fB\fIcommand\fR\fR
76 \fB\-\-command=\fR\fB\fIcommand\fR\fR
80 is to execute the given command string,
81 \fIcommand\fR\&. This option can be repeated and combined in any order with the
89 does not read commands from standard input; instead it terminates after processing all the
93 options in sequence\&.
96 must be either a command string that is completely parsable by the server (i\&.e\&., it contains no
97 psql\-specific features), or a single backslash command\&. Thus you cannot mix
101 meta\-commands within a
103 option\&. To achieve that, you could use repeated
105 options or pipe the string into
112 psql \-c \*(Aq\ex\*(Aq \-c \*(AqSELECT * FROM foo;\*(Aq
124 echo \*(Aq\ex \e\e SELECT * FROM foo;\*(Aq | psql
131 is the separator meta\-command\&.)
135 command string passed to
137 is sent to the server as a single request\&. Because of this, the server executes it as a single transaction even if the string contains multiple
139 commands, unless there are explicit
140 \fBBEGIN\fR/\fBCOMMIT\fR
141 commands included in the string to divide it into multiple transactions\&. (See
143 for more details about how the server handles multi\-query strings\&.)
145 If having several commands executed in one transaction is not desired, use repeated
147 commands or feed multiple commands to
148 psql\*(Aqs standard input, either using
150 as illustrated above, or via a shell here\-document, for example:
170 (Comma\-Separated Values) output mode\&. This is equivalent to
171 \fB\epset format csv\fR\&.
174 \fB\-d \fR\fB\fIdbname\fR\fR
176 \fB\-\-dbname=\fR\fB\fIdbname\fR\fR
178 Specifies the name of the database to connect to\&. This is equivalent to specifying
180 as the first non\-option argument on the command line\&. The
183 connection string\&. If so, connection string parameters will override any conflicting command line options\&.
188 \fB\-\-echo\-queries\fR
190 Copy all SQL commands sent to the server to standard output as well\&. This is equivalent to setting the variable
198 \fB\-\-echo\-hidden\fR
200 Echo the actual queries generated by
202 and other backslash commands\&. You can use this to study
203 psql\*(Aqs internal operations\&. This is equivalent to setting the variable
209 \fB\-f \fR\fB\fIfilename\fR\fR
211 \fB\-\-file=\fR\fB\fIfilename\fR\fR
213 Read commands from the file
214 \fIfilename\fR, rather than standard input\&. This option can be repeated and combined in any order with the
216 option\&. When either
222 does not read commands from standard input; instead it terminates after processing all the
226 options in sequence\&. Except for that, this option is largely equivalent to the meta\-command
233 (hyphen), then standard input is read until an EOF indication or
235 meta\-command\&. This can be used to intersperse interactive input with input from files\&. Note however that Readline is not used in this case (much as if
237 had been specified)\&.
239 Using this option is subtly different from writing
240 psql < \fIfilename\fR\&. In general, both will do what you expect, but using
242 enables some nice features such as error messages with line numbers\&. There is also a slight chance that using this option will reduce the start\-up overhead\&. On the other hand, the variant using the shell\*(Aqs input redirection is (in theory) guaranteed to yield exactly the same output you would have received had you entered everything by hand\&.
245 \fB\-F \fR\fB\fIseparator\fR\fR
247 \fB\-\-field\-separator=\fR\fB\fIseparator\fR\fR
251 as the field separator for unaligned output\&. This is equivalent to
252 \fB\epset fieldsep\fR
257 \fB\-h \fR\fB\fIhostname\fR\fR
259 \fB\-\-host=\fR\fB\fIhostname\fR\fR
261 Specifies the host name of the machine on which the server is running\&. If the value begins with a slash, it is used as the directory for the Unix\-domain socket\&.
270 output mode\&. This is equivalent to
271 \fB\epset format html\fR
281 List all available databases, then exit\&. Other non\-connection options are ignored\&. This is similar to the meta\-command
284 When this option is used,
286 will connect to the database
287 postgres, unless a different database is named on the command line (option
289 or non\-option argument, possibly via a service entry, but not via an environment variable)\&.
292 \fB\-L \fR\fB\fIfilename\fR\fR
294 \fB\-\-log\-file=\fR\fB\fIfilename\fR\fR
296 Write all query output into file
297 \fIfilename\fR, in addition to the normal output destination\&.
302 \fB\-\-no\-readline\fR
306 for line editing and do not use the command history (see
307 the section called \(lqCommand\-Line Editing\(rq
311 \fB\-o \fR\fB\fIfilename\fR\fR
313 \fB\-\-output=\fR\fB\fIfilename\fR\fR
315 Put all query output into file
316 \fIfilename\fR\&. This is equivalent to the command
320 \fB\-p \fR\fB\fIport\fR\fR
322 \fB\-\-port=\fR\fB\fIport\fR\fR
324 Specifies the TCP port or the local Unix\-domain socket file extension on which the server is listening for connections\&. Defaults to the value of the
326 environment variable or, if not set, to the port specified at compile time, usually 5432\&.
329 \fB\-P \fR\fB\fIassignment\fR\fR
331 \fB\-\-pset=\fR\fB\fIassignment\fR\fR
333 Specifies printing options, in the style of
334 \fB\epset\fR\&. Note that here you have to separate name and value with an equal sign instead of a space\&. For example, to set the output format to
335 LaTeX, you could write
345 should do its work quietly\&. By default, it prints welcome messages and various informational output\&. If this option is used, none of this happens\&. This is useful with the
347 option\&. This is equivalent to setting the variable
353 \fB\-R \fR\fB\fIseparator\fR\fR
355 \fB\-\-record\-separator=\fR\fB\fIseparator\fR\fR
359 as the record separator for unaligned output\&. This is equivalent to
360 \fB\epset recordsep\fR\&.
365 \fB\-\-single\-step\fR
367 Run in single\-step mode\&. That means the user is prompted before each command is sent to the server, with the option to cancel execution as well\&. Use this to debug scripts\&.
372 \fB\-\-single\-line\fR
374 Runs in single\-line mode where a newline terminates an SQL command, as a semicolon does\&.
380 .nr an-no-space-flag 1
387 This mode is provided for those who insist on it, but you are not necessarily encouraged to use it\&. In particular, if you mix
389 and meta\-commands on a line the order of execution might not always be clear to the inexperienced user\&.
396 \fB\-\-tuples\-only\fR
398 Turn off printing of column names and result row count footers, etc\&. This is equivalent to
401 \fB\epset tuples_only\fR\&.
404 \fB\-T \fR\fB\fItable_options\fR\fR
406 \fB\-\-table\-attr=\fR\fB\fItable_options\fR\fR
408 Specifies options to be placed within the
412 \fB\epset tableattr\fR
416 \fB\-U \fR\fB\fIusername\fR\fR
418 \fB\-\-username=\fR\fB\fIusername\fR\fR
420 Connect to the database as the user
422 instead of the default\&. (You must have permission to do so, of course\&.)
425 \fB\-v \fR\fB\fIassignment\fR\fR
427 \fB\-\-set=\fR\fB\fIassignment\fR\fR
429 \fB\-\-variable=\fR\fB\fIassignment\fR\fR
431 Perform a variable assignment, like the
433 meta\-command\&. Note that you must separate name and value, if any, by an equal sign on the command line\&. To unset a variable, leave off the equal sign\&. To set a variable with an empty value, use the equal sign but leave off the value\&. These assignments are done during command line processing, so variables that reflect connection state will get overwritten later\&.
447 \fB\-\-no\-password\fR
449 Never issue a password prompt\&. If the server requires password authentication and a password is not available from other sources such as a
451 file, the connection attempt will fail\&. This option can be useful in batch jobs and scripts where no user is present to enter a password\&.
453 Note that this option will remain set for the entire session, and so it affects uses of the meta\-command
455 as well as the initial connection attempt\&.
464 to prompt for a password before connecting to a database, even if the password will not be used\&.
466 If the server requires password authentication and a password is not available from other sources such as a
470 will prompt for a password in any case\&. However,
472 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
474 to avoid the extra connection attempt\&.
476 Note that this option will remain set for the entire session, and so it affects uses of the meta\-command
478 as well as the initial connection attempt\&.
485 Turn on the expanded table formatting mode\&. This is equivalent to
488 \fB\epset expanded\fR\&.
495 Do not read the start\-up file (neither the system\-wide
497 file nor the user\*(Aqs
504 \fB\-\-field\-separator\-zero\fR
506 Set the field separator for unaligned output to a zero byte\&. This is equivalent to
507 \fB\epset fieldsep_zero\fR\&.
512 \fB\-\-record\-separator\-zero\fR
514 Set the record separator for unaligned output to a zero byte\&. This is useful for interfacing, for example, with
515 xargs \-0\&. This is equivalent to
516 \fB\epset recordsep_zero\fR\&.
521 \fB\-\-single\-transaction\fR
523 This option can only be used in combination with one or more
531 command before the first such option and a
533 command after the last one, thereby wrapping all the commands into a single transaction\&. If any of the commands fails and the variable
537 command is sent instead\&. This ensures that either all the commands complete successfully, or no changes are applied\&.
539 If the commands themselves contain
542 \fBROLLBACK\fR, this option will not have the desired effects\&. Also, if an individual command cannot be executed inside a transaction block, specifying this option will cause the whole transaction to fail\&.
547 \fB\-\-help[=\fR\fB\fItopic\fR\fR\fB]\fR
551 and exit\&. The optional
553 parameter (defaulting to
554 options) selects which part of
559 psql\*(Aqs backslash commands;
561 describes the command\-line options that can be passed to
566 configuration variables\&.
571 returns 0 to the shell if it finished normally, 1 if a fatal error of its own occurs (e\&.g\&., out of memory, file not found), 2 if the connection to the server went bad and the session was not interactive, and 3 if an error occurred in a script and the variable
575 .SS "Connecting to a Database"
580 client application\&. In order to connect to a database you need to know the name of your target database, the host name and port number of the server, and what database user name you want to connect as\&.
582 can be told about those parameters via command line options, namely
587 respectively\&. If an argument is found that does not belong to any option it will be interpreted as the database name (or the database user name, if the database name is already given)\&. Not all of these options are required; there are useful defaults\&. If you omit the host name,
589 will connect via a Unix\-domain socket to a server on the local host, or via TCP/IP to
591 on Windows\&. The default port number is determined at compile time\&. Since the database server uses the same default, you will not have to specify the port in most cases\&. The default database user name is your operating\-system user name\&. Once the database user name is determined, it is used as the default database name\&. Note that you cannot just connect to any database under any database user name\&. Your database administrator should have informed you about your access rights\&.
593 When the defaults aren\*(Aqt quite right, you can save yourself some typing by setting the environment variables
599 to appropriate values\&. (For additional environment variables, see
600 Section\ \&32.15\&.) It is also convenient to have a
602 file to avoid regularly having to type in passwords\&. See
604 for more information\&.
606 An alternative way to specify connection parameters is in a
609 URI, which is used instead of a database name\&. This mechanism give you very wide control over the connection\&. For example:
615 $ \fBpsql "service=myservice sslmode=require"\fR
616 $ \fBpsql postgresql://dbmaster:5433/mydb?sslmode=require\fR
622 This way you can also use
624 for connection parameter lookup as described in
625 Section\ \&32.18\&. See
627 for more information on all the available connection options\&.
629 If the connection could not be made for any reason (e\&.g\&., insufficient privileges, server is not running on the targeted host, etc\&.),
631 will return an error and terminate\&.
633 If both standard input and standard output are a terminal, then
635 sets the client encoding to
636 \(lqauto\(rq, which will detect the appropriate client encoding from the locale settings (\fBLC_CTYPE\fR
637 environment variable on Unix systems)\&. If this doesn\*(Aqt work out as expected, the client encoding can be overridden using the environment variable
638 \fBPGCLIENTENCODING\fR\&.
639 .SS "Entering SQL Commands"
643 provides a prompt with the name of the database to which
645 is currently connected, followed by the string
654 Type "help" for help\&.
662 At the prompt, the user can type in
664 commands\&. Ordinarily, input lines are sent to the server when a command\-terminating semicolon is reached\&. An end of line does not terminate a command\&. Thus commands can be spread over several lines for clarity\&. If the command was sent and executed without error, the results of the command are displayed on the screen\&.
666 If untrusted users have access to a database that has not adopted a
667 secure schema usage pattern, begin your session by removing publicly\-writable schemas from
668 \fIsearch_path\fR\&. One can add
669 options=\-csearch_path=
670 to the connection string or issue
671 SELECT pg_catalog\&.set_config(\*(Aqsearch_path\*(Aq, \*(Aq\*(Aq, false)
672 before other SQL commands\&. This consideration is not specific to
673 psql; it applies to every interface for executing arbitrary SQL commands\&.
675 Whenever a command is executed,
677 also polls for asynchronous notification events generated by
682 While C\-style block comments are passed to the server for processing and removal, SQL\-standard comments are removed by
686 Anything you enter in
688 that begins with an unquoted backslash is a
690 meta\-command that is processed by
692 itself\&. These commands make
694 more useful for administration or scripting\&. Meta\-commands are often called slash or backslash commands\&.
698 command is the backslash, followed immediately by a command verb, then any arguments\&. The arguments are separated from the command verb and each other by any number of whitespace characters\&.
700 To include whitespace in an argument you can quote it with single quotes\&. To include a single quote in an argument, write two single quotes within single\-quoted text\&. Anything contained in single quotes is furthermore subject to C\-like substitutions for
714 (hexadecimal)\&. A backslash preceding any other character within single\-quoted text quotes that single character, whatever it is\&.
716 If an unquoted colon (:) followed by a
718 variable name appears within an argument, it is replaced by the variable\*(Aqs value, as described in
721 :\*(Aq\fIvariable_name\fR\*(Aq
723 :"\fIvariable_name\fR"
724 described there work as well\&. The
725 :{?\fIvariable_name\fR}
726 syntax allows testing whether a variable is defined\&. It is substituted by TRUE or FALSE\&. Escaping the colon with a backslash protects it from substitution\&.
728 Within an argument, text that is enclosed in backquotes (`) is taken as a command line that is passed to the shell\&. The output of the command (with any trailing newline removed) replaces the backquoted text\&. Within the text enclosed in backquotes, no special quoting or other processing occurs, except that appearances of
734 variable name are replaced by the variable\*(Aqs value\&. Also, appearances of
735 :\*(Aq\fIvariable_name\fR\*(Aq
736 are replaced by the variable\*(Aqs value suitably quoted to become a single shell command argument\&. (The latter form is almost always preferable, unless you are very sure of what is in the variable\&.) Because carriage return and line feed characters cannot be safely quoted on all platforms, the
737 :\*(Aq\fIvariable_name\fR\*(Aq
738 form prints an error message and does not substitute the variable value when such characters appear in the value\&.
740 Some commands take an
742 identifier (such as a table name) as argument\&. These arguments follow the syntax rules of
743 SQL: Unquoted letters are forced to lowercase, while double quotes (") protect letters from case conversion and allow incorporation of whitespace into the identifier\&. Within double quotes, paired double quotes reduce to a single double quote in the resulting name\&. For example,
751 Parsing for arguments stops at the end of the line, or when another unquoted backslash is found\&. An unquoted backslash is taken as the beginning of a new meta\-command\&. The special sequence
753 (two backslashes) marks the end of arguments and continues parsing
755 commands, if any\&. That way
759 commands can be freely mixed on a line\&. But in any case, the arguments of a meta\-command cannot continue beyond the end of the line\&.
761 Many of the meta\-commands act on the
762 current query buffer\&. This is simply a buffer holding whatever SQL command text has been typed but not yet sent to the server for execution\&. This will include previous input lines as well as any text appearing before the meta\-command on the same line\&.
764 Many of the meta\-commands also allow
766 to be appended as an option\&. This will cause the results to be displayed in expanded mode, as if
769 \fB\epset expanded\fR
772 The following meta\-commands are defined:
776 If the current table output format is unaligned, it is switched to aligned\&. If it is not unaligned, it is set to unaligned\&. This command is kept for backwards compatibility\&. See
778 for a more general solution\&.
781 \ebind [ \fIparameter\fR ] \&.\&.\&.
783 Sets query parameters for the next query execution, with the specified parameters passed for any parameter placeholders ($1
792 INSERT INTO tbl1 VALUES ($1, $2) \ebind \*(Aqfirst value\*(Aq \*(Aqsecond value\*(Aq \eg
798 This also works for query\-execution commands besides
804 This command causes the extended query protocol (see
805 Section\ \&54.1.2) to be used, unlike normal
807 operation, which uses the simple query protocol\&. So this command can be useful to test the extended query protocol from
808 psql\&. (The extended query protocol is used even if the query has no parameters and this command specifies zero parameters\&.) This command affects only the next query executed; all subsequent queries will use the simple query protocol by default\&.
811 \ebind_named \fIstatement_name\fR [ \fIparameter\fR ] \&.\&.\&.
815 \ebind, except that it takes the name of an existing prepared statement as first parameter\&. An empty string denotes the unnamed prepared statement\&.
823 INSERT INTO tbls1 VALUES ($1, $2) \eparse stmt1
824 \ebind_named stmt1 \*(Aqfirst value\*(Aq \*(Aqsecond value\*(Aq \eg
830 This command causes the extended query protocol (see
831 Section\ \&54.1.2) to be used, unlike normal
833 operation, which uses the simple query protocol\&. So this command can be useful to test the extended query protocol from
837 \ec or \econnect [ \-reuse\-previous=\fIon|off\fR ] [ \fIdbname\fR [ \fIusername\fR ] [ \fIhost\fR ] [ \fIport\fR ] | \fIconninfo\fR ]
839 Establishes a new connection to a
841 server\&. The connection parameters to use can be specified either using a positional syntax (one or more of database name, user, host, and port), or using a
843 connection string as detailed in
844 Section\ \&32.1.1\&. If no arguments are given, a new connection is made using the same parameters as before\&.
854 is equivalent to omitting that parameter\&.
856 The new connection can re\-use connection parameters from the previous connection; not only database name, user, host, and port, but other settings such as
857 \fIsslmode\fR\&. By default, parameters are re\-used in the positional syntax, but not when a
859 string is given\&. Passing a first argument of
862 \-reuse\-previous=off
863 overrides that default\&. If parameters are re\-used, then any parameter not explicitly specified as a positional parameter or in the
865 string is taken from the existing connection\*(Aqs parameters\&. An exception is that if the
867 setting is changed from its previous value using the positional syntax, any
869 setting present in the existing connection\*(Aqs parameters is dropped\&. Also, any password used for the existing connection will be re\-used only if the user, host, and port settings are not changed\&. When the command neither specifies nor reuses a particular parameter, the
873 If the new connection is successfully made, the previous connection is closed\&. If the connection attempt fails (wrong user name, access denied, etc\&.), the previous connection will be kept if
875 is in interactive mode\&. But when executing a non\-interactive script, the old connection is closed and an error is reported\&. That may or may not terminate the script; if it does not, all database\-accessing commands will fail until another
877 command is successfully executed\&. This distinction was chosen as a user convenience against typos on the one hand, and a safety mechanism that scripts are not accidentally acting on the wrong database on the other hand\&. Note that whenever a
879 command attempts to re\-use parameters, the values re\-used are those of the last successful connection, not of any failed attempts made subsequently\&. However, in the case of a non\-interactive
881 failure, no parameters are allowed to be re\-used later, since the script would likely be expecting the values from the failed
891 => \ec mydb myuser host\&.dom 6432
893 => \ec "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable"
894 => \ec \-reuse\-previous=on sslmode=require \-\- changes only sslmode
895 => \ec postgresql://tom@localhost/mydb?application_name=myapp
904 Sets the title of any tables being printed as the result of a query or unset any such title\&. This command is equivalent to
905 \epset title \fItitle\fR\&. (The name of this command derives from
906 \(lqcaption\(rq, as it was previously only used to set the caption in an
911 \ecd [ \fIdirectory\fR ]
913 Changes the current working directory to
914 \fIdirectory\fR\&. Without argument, changes to the current user\*(Aqs home directory\&. For details on how home directories are found, see
921 .nr an-no-space-flag 1
928 To print your current working directory, use
934 \eclose_prepared \fIprepared_statement_name\fR
936 Closes the specified prepared statement\&. An empty string denotes the unnamed prepared statement\&. If no prepared statement exists with this name, the operation is a no\-op\&.
944 SELECT $1 \eparse stmt1
945 \eclose_prepared stmt1
951 This command causes the extended query protocol to be used, unlike normal
953 operation, which uses the simple query protocol\&. So this command can be useful to test the extended query protocol from
959 Outputs information about the current database connection, including SSL\-related information if SSL is in use\&.
963 field shows the user at the time of connection, while the
965 field indicates whether the current user (in the current execution context) has superuser privileges\&. These users are usually the same, but they can differ, for example, if the current user was changed with the
970 \ecopy { \fItable\fR [ ( \fIcolumn_list\fR ) ] } from { \fI\*(Aqfilename\*(Aq\fR | program \fI\*(Aqcommand\*(Aq\fR | stdin | pstdin } [ [ with ] ( \fIoption\fR [, \&.\&.\&.] ) ] [ where \fIcondition\fR ]
972 \ecopy { \fItable\fR [ ( \fIcolumn_list\fR ) ] | ( \fIquery\fR ) } to { \fI\*(Aqfilename\*(Aq\fR | program \fI\*(Aqcommand\*(Aq\fR | stdout | pstdout } [ [ with ] ( \fIoption\fR [, \&.\&.\&.] ) ]
974 Performs a frontend (client) copy\&. This is an operation that runs an
977 command, but instead of the server reading or writing the specified file,
979 reads or writes the file and routes the data between the server and the local file system\&. This means that file accessibility and privileges are those of the local user, not the server, and no SQL superuser privileges are required\&.
987 and the data passed from or to
989 is routed between the server and the client\&. Again, the execution privileges are those of the local user, not the server, and no SQL superuser privileges are required\&.
992 \ecopy \&.\&.\&. from stdin, data rows are read from the same source that issued the command, continuing until a line containing only
994 is read or the stream reaches
995 EOF\&. This option is useful for populating tables in\-line within an SQL script file\&. For
996 \ecopy \&.\&.\&. to stdout, output is sent to the same place as
998 command output, and the
1000 command status is not printed (since it might be confused with a data row)\&. To read/write
1001 psql\*(Aqs standard input or output regardless of the current command source or
1008 The syntax of this command is similar to that of the
1011 command\&. All options other than the data source/destination are as specified for
1012 \fBCOPY\fR\&. Because of this, special parsing rules apply to the
1014 meta\-command\&. Unlike most other meta\-commands, the entire remainder of the line is always taken to be the arguments of
1015 \fB\ecopy\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&.
1021 .nr an-no-space-flag 1
1028 Another way to obtain the same result as
1032 COPY \&.\&.\&. TO STDOUT
1033 command and terminate it with
1036 \eg |\fIprogram\fR\&. Unlike
1037 \ecopy, this method allows the command to span multiple lines; also, variable interpolation and backquote expansion can be used\&.
1045 .nr an-no-space-flag 1
1052 These operations are not as efficient as the
1055 command with a file or program data source or destination, because all data must pass through the client/server connection\&. For large amounts of data the
1057 command might be preferable\&.
1064 Shows the copyright and distribution terms of
1068 \ecrosstabview [ \fIcolV\fR [ \fIcolH\fR [ \fIcolD\fR [ \fIsortcolH\fR ] ] ] ]
1070 Executes the current query buffer (like
1071 \eg) and shows the results in a crosstab grid\&. The query must return at least three columns\&. The output column identified by
1073 becomes a vertical header and the output column identified by
1075 becomes a horizontal header\&.
1077 identifies the output column to display within the grid\&.
1079 identifies an optional sort column for the horizontal header\&.
1081 Each column specification can be a column number (starting at 1) or a column name\&. The usual SQL case folding and quoting rules apply to column names\&. If omitted,
1083 is taken as column 1 and
1090 is not specified, then there must be exactly three columns in the query result, and the column that is neither
1097 The vertical header, displayed as the leftmost column, contains the values found in column
1098 \fIcolV\fR, in the same order as in the query results, but with duplicates removed\&.
1100 The horizontal header, displayed as the first row, contains the values found in column
1101 \fIcolH\fR, with duplicates removed\&. By default, these appear in the same order as in the query results\&. But if the optional
1103 argument is given, it identifies a column whose values must be integer numbers, and the values from
1105 will appear in the horizontal header sorted according to the corresponding
1109 Inside the crosstab grid, for each distinct value
1113 and each distinct value
1116 \fIcolV\fR, the cell located at the intersection
1118 contains the value of the
1120 column in the query result row for which the value of
1127 y\&. If there is no such row, the cell is empty\&. If there are multiple such rows, an error is reported\&.
1130 \ed[Sx+] [ \fIpattern\fR ]
1132 For each relation (table, view, materialized view, index, sequence, or foreign table) or composite type matching the
1133 \fIpattern\fR, show all columns, their types, the tablespace (if not the default) and any special attributes such as
1135 or defaults\&. Associated indexes, constraints, rules, and triggers are also shown\&. For foreign tables, the associated foreign server is shown as well\&. (\(lqMatching the pattern\(rq
1140 For some types of relation,
1142 shows additional information for each column: column values for sequences, indexed expressions for indexes, and foreign data wrapper options for foreign tables\&.
1146 is identical, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table, the view definition if the relation is a view, a non\-default
1150 name if the relation has an access method\&.
1152 By default, only user\-created objects are shown; supply a pattern or the
1154 modifier to include system objects\&.
1160 .nr an-no-space-flag 1
1171 argument, it is equivalent to
1173 which will show a list of all visible tables, views, materialized views, sequences and foreign tables\&. This is purely a convenience measure\&.
1175 As with many other commands, if
1177 is appended to the command name, the results are displayed in expanded mode, but note that this only applies when
1183 modifier cannot appear immediately after the
1187 is a different command); the
1189 modifier may only appear after an
1193 modifier\&. For example,
1197 and will show a list of all relations in expanded mode\&.
1202 \eda[Sx] [ \fIpattern\fR ]
1204 Lists aggregate functions, together with their return type and the data types they operate on\&. If
1206 is specified, only aggregates whose names match the pattern are shown\&. By default, only user\-created objects are shown; supply a pattern or the
1208 modifier to include system objects\&. If
1210 is appended to the command name, the results are displayed in expanded mode\&.
1213 \edA[x+] [ \fIpattern\fR ]
1215 Lists access methods\&. If
1217 is specified, only access methods whose names match the pattern are shown\&. If
1219 is appended to the command name, the results are displayed in expanded mode\&. If
1221 is appended to the command name, each access method is listed with its associated handler function and description\&.
1224 \edAc[x+] [\fIaccess\-method\-pattern\fR [\fIinput\-type\-pattern\fR]]
1226 Lists operator classes (see
1227 Section\ \&36.16.1)\&. If
1228 \fIaccess\-method\-pattern\fR
1229 is specified, only operator classes associated with access methods whose names match that pattern are listed\&. If
1230 \fIinput\-type\-pattern\fR
1231 is specified, only operator classes associated with input types whose names match that pattern are listed\&. If
1233 is appended to the command name, the results are displayed in expanded mode\&. If
1235 is appended to the command name, each operator class is listed with its associated operator family and owner\&.
1238 \edAf[x+] [\fIaccess\-method\-pattern\fR [\fIinput\-type\-pattern\fR]]
1240 Lists operator families (see
1241 Section\ \&36.16.5)\&. If
1242 \fIaccess\-method\-pattern\fR
1243 is specified, only operator families associated with access methods whose names match that pattern are listed\&. If
1244 \fIinput\-type\-pattern\fR
1245 is specified, only operator families associated with input types whose names match that pattern are listed\&. If
1247 is appended to the command name, the results are displayed in expanded mode\&. If
1249 is appended to the command name, each operator family is listed with its owner\&.
1252 \edAo[x+] [\fIaccess\-method\-pattern\fR [\fIoperator\-family\-pattern\fR]]
1254 Lists operators associated with operator families (see
1255 Section\ \&36.16.2)\&. If
1256 \fIaccess\-method\-pattern\fR
1257 is specified, only members of operator families associated with access methods whose names match that pattern are listed\&. If
1258 \fIoperator\-family\-pattern\fR
1259 is specified, only members of operator families whose names match that pattern are listed\&. If
1261 is appended to the command name, the results are displayed in expanded mode\&. If
1263 is appended to the command name, each operator is listed with its sort operator family (if it is an ordering operator), and whether its underlying function is leakproof\&.
1266 \edAp[x+] [\fIaccess\-method\-pattern\fR [\fIoperator\-family\-pattern\fR]]
1268 Lists support functions associated with operator families (see
1269 Section\ \&36.16.3)\&. If
1270 \fIaccess\-method\-pattern\fR
1271 is specified, only functions of operator families associated with access methods whose names match that pattern are listed\&. If
1272 \fIoperator\-family\-pattern\fR
1273 is specified, only functions of operator families whose names match that pattern are listed\&. If
1275 is appended to the command name, the results are displayed in expanded mode\&. If
1277 is appended to the command name, functions are displayed verbosely, with their actual parameter lists\&.
1280 \edb[x+] [ \fIpattern\fR ]
1282 Lists tablespaces\&. If
1284 is specified, only tablespaces whose names match the pattern are shown\&. If
1286 is appended to the command name, the results are displayed in expanded mode\&. If
1288 is appended to the command name, each tablespace is listed with its associated options, on\-disk size, permissions and description\&.
1291 \edc[Sx+] [ \fIpattern\fR ]
1293 Lists conversions between character\-set encodings\&. If
1295 is specified, only conversions whose names match the pattern are listed\&. By default, only user\-created objects are shown; supply a pattern or the
1297 modifier to include system objects\&. If
1299 is appended to the command name, the results are displayed in expanded mode\&. If
1301 is appended to the command name, each object is listed with its associated description\&.
1304 \edconfig[x+] [ \fIpattern\fR ]
1306 Lists server configuration parameters and their values\&. If
1308 is specified, only parameters whose names match the pattern are listed\&. Without a
1309 \fIpattern\fR, only parameters that are set to non\-default values are listed\&. (Use
1311 to see all parameters\&.) If
1313 is appended to the command name, the results are displayed in expanded mode\&. If
1315 is appended to the command name, each parameter is listed with its data type, context in which the parameter can be set, and access privileges (if non\-default access privileges have been granted)\&.
1318 \edC[x+] [ \fIpattern\fR ]
1320 Lists type casts\&. If
1322 is specified, only casts whose source or target types match the pattern are listed\&. If
1324 is appended to the command name, the results are displayed in expanded mode\&. If
1326 is appended to the command name, additional information about each cast is shown, including whether its underlying function is leakproof, and the cast\*(Aqs description\&.
1329 \edd[Sx] [ \fIpattern\fR ]
1331 Shows the descriptions of objects of type
1336 trigger\&. All other comments may be viewed by the respective backslash commands for those object types\&.
1339 displays descriptions for objects matching the
1340 \fIpattern\fR, or of visible objects of the appropriate type if no argument is given\&. But in either case, only objects that have a description are listed\&. By default, only user\-created objects are shown; supply a pattern or the
1342 modifier to include system objects\&. If
1344 is appended to the command name, the results are displayed in expanded mode\&.
1346 Descriptions for objects can be created with the
1352 \edD[Sx+] [ \fIpattern\fR ]
1356 is specified, only domains whose names match the pattern are shown\&. By default, only user\-created objects are shown; supply a pattern or the
1358 modifier to include system objects\&. If
1360 is appended to the command name, the results are displayed in expanded mode\&. If
1362 is appended to the command name, each object is listed with its associated permissions and description\&.
1365 \eddp[x] [ \fIpattern\fR ]
1367 Lists default access privilege settings\&. An entry is shown for each role (and schema, if applicable) for which the default privilege settings have been changed from the built\-in defaults\&. If
1369 is specified, only entries whose role name or schema name matches the pattern are listed\&. If
1371 is appended to the command name, the results are displayed in expanded mode\&.
1374 \fBALTER DEFAULT PRIVILEGES\fR
1375 command is used to set default access privileges\&. The meaning of the privilege display is explained in
1379 \edE[Sx+] [ \fIpattern\fR ]
1381 \edi[Sx+] [ \fIpattern\fR ]
1383 \edm[Sx+] [ \fIpattern\fR ]
1385 \eds[Sx+] [ \fIpattern\fR ]
1387 \edt[Sx+] [ \fIpattern\fR ]
1389 \edv[Sx+] [ \fIpattern\fR ]
1391 In this group of commands, the letters
1398 stand for foreign table, index, materialized view, sequence, table, and view, respectively\&. You can specify any or all of these letters, in any order, to obtain a listing of objects of these types\&. For example,
1400 lists tables and indexes\&. If
1402 is appended to the command name, the results are displayed in expanded mode\&. If
1404 is appended to the command name, each object is listed with its persistence status (permanent, temporary, or unlogged), physical size on disk, and associated description if any\&. If
1406 is specified, only objects whose names match the pattern are listed\&. By default, only user\-created objects are shown; supply a pattern or the
1408 modifier to include system objects\&.
1411 \edes[x+] [ \fIpattern\fR ]
1413 Lists foreign servers (mnemonic:
1414 \(lqexternal servers\(rq)\&. If
1416 is specified, only those servers whose name matches the pattern are listed\&. If
1418 is appended to the command name, the results are displayed in expanded mode\&. If
1420 is appended to the command name, a full description of each server is shown, including the server\*(Aqs access privileges, type, version, options, and description\&.
1423 \edet[x+] [ \fIpattern\fR ]
1425 Lists foreign tables (mnemonic:
1426 \(lqexternal tables\(rq)\&. If
1428 is specified, only entries whose table name or schema name matches the pattern are listed\&. If
1430 is appended to the command name, the results are displayed in expanded mode\&. If
1432 is appended to the command name, generic options and the foreign table description are also displayed\&.
1435 \edeu[x+] [ \fIpattern\fR ]
1437 Lists user mappings (mnemonic:
1438 \(lqexternal users\(rq)\&. If
1440 is specified, only those mappings whose user names match the pattern are listed\&. If
1442 is appended to the command name, the results are displayed in expanded mode\&. If
1444 is appended to the command name, additional information about each mapping is shown\&.
1450 .nr an-no-space-flag 1
1458 might also display the user name and password of the remote user, so care should be taken not to disclose them\&.
1463 \edew[x+] [ \fIpattern\fR ]
1465 Lists foreign\-data wrappers (mnemonic:
1466 \(lqexternal wrappers\(rq)\&. If
1468 is specified, only those foreign\-data wrappers whose name matches the pattern are listed\&. If
1470 is appended to the command name, the results are displayed in expanded mode\&. If
1472 is appended to the command name, the access privileges, options, and description of the foreign\-data wrapper are also shown\&.
1475 \edf[anptwSx+] [ \fIpattern\fR [ \fIarg_pattern\fR \&.\&.\&. ] ]
1477 Lists functions, together with their result data types, argument data types, and function types, which are classified as
1483 \(lqwindow\(rq\&. To display only functions of specific type(s), add the corresponding letters
1489 to the command\&. If
1491 is specified, only functions whose names match the pattern are shown\&. Any additional arguments are type\-name patterns, which are matched to the type names of the first, second, and so on arguments of the function\&. (Matching functions can have more arguments than what you specify\&. To prevent that, write a dash
1494 \fIarg_pattern\fR\&.) By default, only user\-created objects are shown; supply a pattern or the
1496 modifier to include system objects\&. If
1498 is appended to the command name, the results are displayed in expanded mode\&. If
1500 is appended to the command name, additional information about each function is shown, including volatility, parallel safety, owner, security classification, whether it is leakproof, access privileges, language, internal name (for C and internal functions only), and description\&. Source code for a specific function can be seen using
1504 \edF[x+] [ \fIpattern\fR ]
1506 Lists text search configurations\&. If
1508 is specified, only configurations whose names match the pattern are shown\&. If
1510 is appended to the command name, the results are displayed in expanded mode\&. If
1512 is appended to the command name, a full description of each configuration is shown, including the underlying text search parser and the dictionary list for each parser token type\&.
1515 \edFd[x+] [ \fIpattern\fR ]
1517 Lists text search dictionaries\&. If
1519 is specified, only dictionaries whose names match the pattern are shown\&. If
1521 is appended to the command name, the results are displayed in expanded mode\&. If
1523 is appended to the command name, additional information is shown about each selected dictionary, including the underlying text search template and the option values\&.
1526 \edFp[x+] [ \fIpattern\fR ]
1528 Lists text search parsers\&. If
1530 is specified, only parsers whose names match the pattern are shown\&. If
1532 is appended to the command name, the results are displayed in expanded mode\&. If
1534 is appended to the command name, a full description of each parser is shown, including the underlying functions and the list of recognized token types\&.
1537 \edFt[x+] [ \fIpattern\fR ]
1539 Lists text search templates\&. If
1541 is specified, only templates whose names match the pattern are shown\&. If
1543 is appended to the command name, the results are displayed in expanded mode\&. If
1545 is appended to the command name, additional information is shown about each template, including the underlying function names\&.
1548 \edg[Sx+] [ \fIpattern\fR ]
1550 Lists database roles\&. (Since the concepts of
1554 have been unified into
1555 \(lqroles\(rq, this command is now equivalent to
1556 \edu\&.) By default, only user\-created roles are shown; supply the
1558 modifier to include system roles\&. If
1560 is specified, only those roles whose names match the pattern are listed\&. If
1562 is appended to the command name, the results are displayed in expanded mode\&. If
1564 is appended to the command name, additional information is shown about each role; currently this adds the comment for each role\&.
1569 This is an alias for
1570 \fB\elo_list\fR, which shows a list of large objects\&. If
1572 is appended to the command name, the results are displayed in expanded mode\&. If
1574 is appended to the command name, each large object is listed with its associated permissions, if any\&.
1577 \edL[Sx+] [ \fIpattern\fR ]
1579 Lists procedural languages\&. If
1581 is specified, only languages whose names match the pattern are listed\&. By default, only user\-created languages are shown; supply the
1583 modifier to include system objects\&. If
1585 is appended to the command name, the results are displayed in expanded mode\&. If
1587 is appended to the command name, each language is listed with its call handler, validator, access privileges, and whether it is a system object\&.
1590 \edn[Sx+] [ \fIpattern\fR ]
1592 Lists schemas (namespaces)\&. If
1594 is specified, only schemas whose names match the pattern are listed\&. By default, only user\-created objects are shown; supply a pattern or the
1596 modifier to include system objects\&. If
1598 is appended to the command name, the results are displayed in expanded mode\&. If
1600 is appended to the command name, each object is listed with its associated permissions and description, if any\&.
1603 \edo[Sx+] [ \fIpattern\fR [ \fIarg_pattern\fR [ \fIarg_pattern\fR ] ] ]
1605 Lists operators with their operand and result types\&. If
1607 is specified, only operators whose names match the pattern are listed\&. If one
1609 is specified, only prefix operators whose right argument\*(Aqs type name matches that pattern are listed\&. If two
1610 \fIarg_pattern\fRs are specified, only binary operators whose argument type names match those patterns are listed\&. (Alternatively, write
1612 for the unused argument of a unary operator\&.) By default, only user\-created objects are shown; supply a pattern or the
1614 modifier to include system objects\&. If
1616 is appended to the command name, the results are displayed in expanded mode\&. If
1618 is appended to the command name, additional information about each operator is shown, including the name of the underlying function, and whether it is leakproof\&.
1621 \edO[Sx+] [ \fIpattern\fR ]
1623 Lists collations\&. If
1625 is specified, only collations whose names match the pattern are listed\&. By default, only user\-created objects are shown; supply a pattern or the
1627 modifier to include system objects\&. If
1629 is appended to the command name, the results are displayed in expanded mode\&. If
1631 is appended to the command name, each collation is listed with its associated description, if any\&. Note that only collations usable with the current database\*(Aqs encoding are shown, so the results may vary in different databases of the same installation\&.
1634 \edp[Sx] [ \fIpattern\fR ]
1636 Lists tables, views and sequences with their associated access privileges\&. If
1638 is specified, only tables, views and sequences whose names match the pattern are listed\&. By default only user\-created objects are shown; supply a pattern or the
1640 modifier to include system objects\&. If
1642 is appended to the command name, the results are displayed in expanded mode\&.
1648 commands are used to set access privileges\&. The meaning of the privilege display is explained in
1652 \edP[itnx+] [ \fIpattern\fR ]
1654 Lists partitioned relations\&. If
1656 is specified, only entries whose name matches the pattern are listed\&. The modifiers
1660 (indexes) can be appended to the command, filtering the kind of relations to list\&. By default, partitioned tables and indexes are listed\&.
1664 (\(lqnested\(rq) is used, or a pattern is specified, then non\-root partitioned relations are included, and a column is shown displaying the parent of each partitioned relation\&.
1668 is appended to the command name, the results are displayed in expanded mode\&. If
1670 is appended to the command name, the sum of the sizes of each relation\*(Aqs partitions is also displayed, along with the relation\*(Aqs description\&. If
1673 +, two sizes are shown: one including the total size of directly\-attached leaf partitions, and another showing the total size of all partitions, including indirectly attached sub\-partitions\&.
1676 \edrds[x] [ \fIrole\-pattern\fR [ \fIdatabase\-pattern\fR ] ]
1678 Lists defined configuration settings\&. These settings can be role\-specific, database\-specific, or both\&.
1681 \fIdatabase\-pattern\fR
1682 are used to select specific roles and databases to list, respectively\&. If omitted, or if
1684 is specified, all settings are listed, including those not role\-specific or database\-specific, respectively\&. If
1686 is appended to the command name, the results are displayed in expanded mode\&.
1691 \fBALTER DATABASE\fR
1692 commands are used to define per\-role and per\-database configuration settings\&.
1695 \edrg[Sx] [ \fIpattern\fR ]
1697 Lists information about each granted role membership, including assigned options (ADMIN,
1700 SET) and grantor\&. See the
1702 command for information about role memberships\&.
1704 By default, only grants to user\-created roles are shown; supply the
1706 modifier to include system roles\&. If
1708 is specified, only grants to those roles whose names match the pattern are listed\&. If
1710 is appended to the command name, the results are displayed in expanded mode\&.
1713 \edRp[x+] [ \fIpattern\fR ]
1715 Lists replication publications\&. If
1717 is specified, only those publications whose names match the pattern are listed\&. If
1719 is appended to the command name, the results are displayed in expanded mode\&. If
1721 is appended to the command name, the tables and schemas associated with each publication are shown as well\&.
1724 \edRs[x+] [ \fIpattern\fR ]
1726 Lists replication subscriptions\&. If
1728 is specified, only those subscriptions whose names match the pattern are listed\&. If
1730 is appended to the command name, the results are displayed in expanded mode\&. If
1732 is appended to the command name, additional properties of the subscriptions are shown\&.
1735 \edT[Sx+] [ \fIpattern\fR ]
1737 Lists data types\&. If
1739 is specified, only types whose names match the pattern are listed\&. If
1741 is appended to the command name, the results are displayed in expanded mode\&. If
1743 is appended to the command name, each type is listed with its internal name and size, its allowed values if it is an
1745 type, and its associated permissions\&. By default, only user\-created objects are shown; supply a pattern or the
1747 modifier to include system objects\&.
1750 \edu[Sx+] [ \fIpattern\fR ]
1752 Lists database roles\&. (Since the concepts of
1756 have been unified into
1757 \(lqroles\(rq, this command is now equivalent to
1758 \edg\&.) By default, only user\-created roles are shown; supply the
1760 modifier to include system roles\&. If
1762 is specified, only those roles whose names match the pattern are listed\&. If
1764 is appended to the command name, the results are displayed in expanded mode\&. If
1766 is appended to the command name, additional information is shown about each role; currently this adds the comment for each role\&.
1769 \edx[x+] [ \fIpattern\fR ]
1771 Lists installed extensions\&. If
1773 is specified, only those extensions whose names match the pattern are listed\&. If
1775 is appended to the command name, the results are displayed in expanded mode\&. If
1777 is appended to the command name, all the objects belonging to each matching extension are listed\&.
1780 \edX[x] [ \fIpattern\fR ]
1782 Lists extended statistics\&. If
1784 is specified, only those extended statistics whose names match the pattern are listed\&. If
1786 is appended to the command name, the results are displayed in expanded mode\&.
1788 The status of each kind of extended statistics is shown in a column named after its statistic kind (e\&.g\&. Ndistinct)\&.
1790 means that it was requested when creating the statistics, and NULL means it wasn\*(Aqt requested\&. You can use
1792 if you\*(Aqd like to know whether
1794 was run and statistics are available to the planner\&.
1797 \edy[x+] [ \fIpattern\fR ]
1799 Lists event triggers\&. If
1801 is specified, only those event triggers whose names match the pattern are listed\&. If
1803 is appended to the command name, the results are displayed in expanded mode\&. If
1805 is appended to the command name, each object is listed with its associated description\&.
1808 \ee or \eedit [ \fIfilename\fR ] [ \fIline_number\fR ]
1812 is specified, the file is edited; after the editor exits, the file\*(Aqs content is copied into the current query buffer\&. If no
1814 is given, the current query buffer is copied to a temporary file which is then edited in the same fashion\&. Or, if the current query buffer is empty, the most recently executed query is copied to a temporary file and edited in the same fashion\&.
1816 If you edit a file or the previous query, and you quit the editor without modifying the file, the query buffer is cleared\&. Otherwise, the new contents of the query buffer are re\-parsed according to the normal rules of
1817 psql, treating the whole buffer as a single line\&. Any complete queries are immediately executed; that is, if the query buffer contains or ends with a semicolon, everything up to that point is executed and removed from the query buffer\&. Whatever remains in the query buffer is redisplayed\&. Type semicolon or
1821 to cancel it by clearing the query buffer\&.
1823 Treating the buffer as a single line primarily affects meta\-commands: whatever is in the buffer after a meta\-command will be taken as argument(s) to the meta\-command, even if it spans multiple lines\&. (Thus you cannot make meta\-command\-using scripts this way\&. Use
1827 If a line number is specified,
1829 will position the cursor on the specified line of the file or query buffer\&. Note that if a single all\-digits argument is given,
1831 assumes it is a line number, not a file name\&.
1837 .nr an-no-space-flag 1
1845 Environment, below, for how to configure and customize your editor\&.
1850 \eecho \fItext\fR [ \&.\&.\&. ]
1852 Prints the evaluated arguments to standard output, separated by spaces and followed by a newline\&. This can be useful to intersperse information in the output of scripts\&. For example:
1858 => \fB\eecho `date`\fR
1859 Tue Oct 26 21:40:57 CEST 1999
1865 If the first argument is an unquoted
1867 the trailing newline is not written (nor is the first argument)\&.
1873 .nr an-no-space-flag 1
1882 command to redirect your query output you might wish to use
1884 instead of this command\&. See also
1890 \eef [ \fIfunction_description\fR [ \fIline_number\fR ] ]
1892 This command fetches and edits the definition of the named function or procedure, in the form of a
1893 \fBCREATE OR REPLACE FUNCTION\fR
1895 \fBCREATE OR REPLACE PROCEDURE\fR
1896 command\&. Editing is done in the same way as for
1897 \eedit\&. If you quit the editor without saving, the statement is discarded\&. If you save and exit the editor, the updated command is executed immediately if you added a semicolon to it\&. Otherwise it is redisplayed; type semicolon or
1903 The target function can be specified by name alone, or by name and arguments, for example
1904 foo(integer, text)\&. The argument types must be given if there is more than one function of the same name\&.
1906 If no function is specified, a blank
1907 \fBCREATE FUNCTION\fR
1908 template is presented for editing\&.
1910 If a line number is specified,
1912 will position the cursor on the specified line of the function body\&. (Note that the function body typically does not begin on the first line of the file\&.)
1914 Unlike most other meta\-commands, the entire remainder of the line is always taken to be the argument(s) of
1915 \fB\eef\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&.
1921 .nr an-no-space-flag 1
1929 Environment, below, for how to configure and customize your editor\&.
1934 \eencoding [ \fIencoding\fR ]
1936 Sets the client character set encoding\&. Without an argument, this command shows the current encoding\&.
1941 Repeats the most recent server error message at maximum verbosity, as though
1951 \eev [ \fIview_name\fR [ \fIline_number\fR ] ]
1953 This command fetches and edits the definition of the named view, in the form of a
1954 \fBCREATE OR REPLACE VIEW\fR
1955 command\&. Editing is done in the same way as for
1956 \eedit\&. If you quit the editor without saving, the statement is discarded\&. If you save and exit the editor, the updated command is executed immediately if you added a semicolon to it\&. Otherwise it is redisplayed; type semicolon or
1962 If no view is specified, a blank
1964 template is presented for editing\&.
1966 If a line number is specified,
1968 will position the cursor on the specified line of the view definition\&.
1970 Unlike most other meta\-commands, the entire remainder of the line is always taken to be the argument(s) of
1971 \fB\eev\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&.
1974 \ef [ \fIstring\fR ]
1976 Sets the field separator for unaligned query output\&. The default is the vertical bar (|)\&. It is equivalent to
1977 \fB\epset fieldsep\fR\&.
1980 \eg [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ \fIfilename\fR ]
1982 \eg [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ |\fIcommand\fR ]
1984 Sends the current query buffer to the server for execution\&.
1986 If parentheses appear after
1987 \eg, they surround a space\-separated list of
1988 \fIoption\fR=\fIvalue\fR
1989 formatting\-option clauses, which are interpreted in the same way as
1993 commands, but take effect only for the duration of this query\&. In this list, spaces are not allowed around
1995 signs, but are required between option clauses\&. If
1997 is omitted, the named
1999 is changed in the same way as for
2009 argument is given, the query\*(Aqs output is written to the named file or piped to the given shell command, instead of displaying it as usual\&. The file or command is written to only if the query successfully returns zero or more tuples, not if the query fails or is a non\-data\-returning SQL command\&.
2011 If the current query buffer is empty, the most recently sent query is re\-executed instead\&. Except for that behavior,
2013 without any arguments is essentially equivalent to a semicolon\&. With arguments,
2019 command, and additionally allows one\-shot adjustments of the output formatting options normally set by
2022 When the last argument begins with
2023 |, the entire remainder of the line is taken to be the
2025 to execute, and neither variable interpolation nor backquote expansion are performed in it\&. The rest of the line is simply passed literally to the shell\&.
2030 Shows the description (that is, the column names and data types) of the result of the current query buffer\&. The query is not actually executed; however, if it contains some type of syntax error, that error will be reported in the normal way\&.
2032 If the current query buffer is empty, the most recently sent query is described instead\&.
2035 \egetenv \fIpsql_var\fR \fIenv_var\fR
2037 Gets the value of the environment variable
2039 and assigns it to the
2042 \fIpsql_var\fR\&. If
2044 is not defined in the
2046 process\*(Aqs environment,
2048 is not changed\&. Example:
2054 => \fB\egetenv home HOME\fR
2055 => \fB\eecho :home\fR
2065 Sends the current query buffer to the server, then treats each column of each row of the query\*(Aqs output (if any) as an SQL statement to be executed\&. For example, to create an index on each column of
2072 => \fBSELECT format(\*(Aqcreate index on my_table(%I)\*(Aq, attname)\fR
2073 \-> \fBFROM pg_attribute\fR
2074 \-> \fBWHERE attrelid = \*(Aqmy_table\*(Aq::regclass AND attnum > 0\fR
2075 \-> \fBORDER BY attnum\fR
2086 The generated queries are executed in the order in which the rows are returned, and left\-to\-right within each row if there is more than one column\&. NULL fields are ignored\&. The generated queries are sent literally to the server for processing, so they cannot be
2088 meta\-commands nor contain
2090 variable references\&. If any individual query fails, execution of the remaining queries continues unless
2092 is set\&. Execution of each query is subject to
2094 processing\&. (Setting
2100 is often advisable when using
2101 \fB\egexec\fR\&.) Query logging, single\-step mode, timing, and other query execution features apply to each generated query as well\&.
2103 If the current query buffer is empty, the most recently sent query is re\-executed instead\&.
2106 \egset [ \fIprefix\fR ]
2108 Sends the current query buffer to the server and stores the query\*(Aqs output into
2112 below)\&. The query to be executed must return exactly one row\&. Each column of the row is stored into a separate variable, named the same as the column\&. For example:
2118 => \fBSELECT \*(Aqhello\*(Aq AS var1, 10 AS var2\fR
2120 => \fB\eecho :var1 :var2\fR
2128 \fIprefix\fR, that string is prepended to the query\*(Aqs column names to create the variable names to use:
2134 => \fBSELECT \*(Aqhello\*(Aq AS var1, 10 AS var2\fR
2135 \-> \fB\egset result_\fR
2136 => \fB\eecho :result_var1 :result_var2\fR
2143 If a column result is NULL, the corresponding variable is unset rather than being set\&.
2145 If the query fails or does not return one row, no variables are changed\&.
2147 If the current query buffer is empty, the most recently sent query is re\-executed instead\&.
2150 \egx [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ \fIfilename\fR ]
2152 \egx [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ |\fIcommand\fR ]
2156 \eg, except that it forces expanded output mode for this query, as if
2158 were included in the list of
2164 \eh or \ehelp [ \fIcommand\fR ]
2166 Gives syntax help on the specified
2170 is not specified, then
2172 will list all the commands for which syntax help is available\&. If
2174 is an asterisk (*), then syntax help on all
2176 commands is shown\&.
2178 Unlike most other meta\-commands, the entire remainder of the line is always taken to be the argument(s) of
2179 \fB\ehelp\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&.
2185 .nr an-no-space-flag 1
2192 To simplify typing, commands that consists of several words do not have to be quoted\&. Thus it is fine to type
2193 \fB\ehelp alter table\fR\&.
2202 query output format\&. If the
2204 format is already on, it is switched back to the default aligned text format\&. This command is for compatibility and convenience, but see
2206 about setting other output options\&.
2209 \ei or \einclude \fIfilename\fR
2211 Reads input from the file
2213 and executes it as though it had been typed on the keyboard\&.
2219 (hyphen), then standard input is read until an EOF indication or
2221 meta\-command\&. This can be used to intersperse interactive input with input from files\&. Note that Readline behavior will be used only if it is active at the outermost level\&.
2227 .nr an-no-space-flag 1
2234 If you want to see the lines on the screen as they are read you must set the variable
2242 \eif \fIexpression\fR
2244 \eelif \fIexpression\fR
2250 This group of commands implements nestable conditional blocks\&. A conditional block must begin with an
2253 \fB\eendif\fR\&. In between there may be any number of
2255 clauses, which may optionally be followed by a single
2257 clause\&. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block\&.
2263 commands read their argument(s) and evaluate them as a Boolean expression\&. If the expression yields
2265 then processing continues normally; otherwise, lines are skipped until a matching
2269 is reached\&. Once an
2273 test has succeeded, the arguments of later
2275 commands in the same block are not evaluated but are treated as false\&. Lines following an
2277 are processed only if no earlier matching
2289 command is subject to variable interpolation and backquote expansion, just like any other backslash command argument\&. After that it is evaluated like the value of an on/off option variable\&. So a valid value is any unambiguous case\-insensitive match for one of:
2301 will all be considered to be
2304 Expressions that do not properly evaluate to true or false will generate a warning and be treated as false\&.
2306 Lines being skipped are parsed normally to identify queries and backslash commands, but queries are not sent to the server, and backslash commands other than conditionals (\fB\eif\fR,
2309 \fB\eendif\fR) are ignored\&. Conditional commands are checked only for valid nesting\&. Variable references in skipped lines are not expanded, and backquote expansion is not performed either\&.
2311 All the backslash commands of a given conditional block must appear in the same source file\&. If EOF is reached on the main input file or an
2312 \fB\einclude\fR\-ed file before all local
2313 \fB\eif\fR\-blocks have been closed, then
2315 will raise an error\&.
2323 \-\- check for the existence of two separate records in the database and store
2324 \-\- the results in separate psql variables
2326 EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,
2327 EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee
2330 SELECT * FROM customer WHERE customer_id = 123;
2332 \eecho \*(Aqis not a customer but is an employee\*(Aq
2333 SELECT * FROM employee WHERE employee_id = 456;
2336 \eecho \*(Aqnot a customer or employee\*(Aq
2338 \eecho \*(Aqthis will never print\*(Aq
2347 \eir or \einclude_relative \fIfilename\fR
2351 command is similar to
2352 \ei, but resolves relative file names differently\&. When executing in interactive mode, the two commands behave identically\&. However, when invoked from a script,
2354 interprets file names relative to the directory in which the script is located, rather than the current working directory\&.
2357 \el[x+] or \elist[x+] [ \fIpattern\fR ]
2359 List the databases in the server and show their names, owners, character set encodings, and access privileges\&. If
2361 is specified, only databases whose names match the pattern are listed\&. If
2363 is appended to the command name, the results are displayed in expanded mode\&. If
2365 is appended to the command name, database sizes, default tablespaces, and descriptions are also displayed\&. (Size information is only available for databases that the current user can connect to\&.)
2368 \elo_export \fIloid\fR \fIfilename\fR
2370 Reads the large object with
2373 from the database and writes it to
2374 \fIfilename\fR\&. Note that this is subtly different from the server function
2375 \fBlo_export\fR, which acts with the permissions of the user that the database server runs as and on the server\*(Aqs file system\&.
2381 .nr an-no-space-flag 1
2390 to find out the large object\*(Aqs
2396 \elo_import \fIfilename\fR [ \fIcomment\fR ]
2398 Stores the file into a
2400 large object\&. Optionally, it associates the given comment with the object\&. Example:
2406 foo=> \fB\elo_import \*(Aq/home/peter/pictures/photo\&.xcf\*(Aq \*(Aqa picture of me\*(Aq\fR
2413 The response indicates that the large object received object ID 152801, which can be used to access the newly\-created large object in the future\&. For the sake of readability, it is recommended to always associate a human\-readable comment with every object\&. Both OIDs and comments can be viewed with the
2417 Note that this command is subtly different from the server\-side
2419 because it acts as the local user on the local file system, rather than the server\*(Aqs user and file system\&.
2426 large objects currently stored in the database, along with any comments provided for them\&. If
2428 is appended to the command name, the results are displayed in expanded mode\&. If
2430 is appended to the command name, each large object is listed with its associated permissions, if any\&.
2433 \elo_unlink \fIloid\fR
2435 Deletes the large object with
2438 from the database\&.
2444 .nr an-no-space-flag 1
2453 to find out the large object\*(Aqs
2459 \eo or \eout [ \fIfilename\fR ]
2461 \eo or \eout [ |\fIcommand\fR ]
2463 Arranges to save future query results to the file
2465 or pipe future results to the shell command
2466 \fIcommand\fR\&. If no argument is specified, the query output is reset to the standard output\&.
2468 If the argument begins with
2469 |, then the entire remainder of the line is taken to be the
2471 to execute, and neither variable interpolation nor backquote expansion are performed in it\&. The rest of the line is simply passed literally to the shell\&.
2473 \(lqQuery results\(rq
2474 includes all tables, command responses, and notices obtained from the database server, as well as output of various backslash commands that query the database (such as
2475 \fB\ed\fR); but not error messages\&.
2481 .nr an-no-space-flag 1
2488 To intersperse text output in between query results, use
2496 Print the current query buffer to the standard output\&. If the current query buffer is empty, the most recently executed query is printed instead\&.
2499 \eparse \fIstatement_name\fR
2501 Creates a prepared statement from the current query buffer, based on the name of a destination prepared\-statement object\&. An empty string denotes the unnamed prepared statement\&.
2509 SELECT $1 \eparse stmt1
2515 This command causes the extended query protocol to be used, unlike normal
2517 operation, which uses the simple query protocol\&. A
2519 message will be issued by this command so it can be useful to test the extended query protocol from
2520 psql\&. This command affects only the next query executed; all subsequent queries will use the simple query protocol by default\&.
2523 \epassword [ \fIusername\fR ]
2525 Changes the password of the specified user (by default, the current user)\&. This command prompts for the new password, encrypts it, and sends it to the server as an
2527 command\&. This makes sure that the new password does not appear in cleartext in the command history, the server log, or elsewhere\&.
2530 \eprompt [ \fItext\fR ] \fIname\fR
2532 Prompts the user to supply text, which is assigned to the variable
2533 \fIname\fR\&. An optional prompt string,
2534 \fItext\fR, can be specified\&. (For multiword prompts, surround the text with single quotes\&.)
2538 uses the terminal for input and output\&. However, if the
2540 command line switch was used,
2542 uses standard input and standard output\&.
2545 \epset [ \fIoption\fR [ \fIvalue\fR ] ]
2547 This command sets options affecting the output of query result tables\&.
2549 indicates which option is to be set\&. The semantics of
2551 vary depending on the selected option\&. For some options, omitting
2553 causes the option to be toggled or unset, as described under the particular option\&. If no such behavior is mentioned, then omitting
2555 just results in the current setting being displayed\&.
2558 without any arguments displays the current status of all printing options\&.
2560 Adjustable printing options are:
2566 must be a number\&. In general, the higher the number the more borders and lines the tables will have, but details depend on the particular format\&. In
2568 format, this will translate directly into the
2570 attribute\&. In most other formats only values 0 (no border), 1 (internal dividing lines), and 2 (table frame) make sense, and values above 2 will be treated the same as
2575 formats additionally allow a value of 3 to add dividing lines between data rows\&.
2580 Sets the target width for the
2582 format, and also the width limit for determining whether output is wide enough to require the pager or switch to the vertical display in expanded auto mode\&. Zero (the default) causes the target width to be controlled by the environment variable
2583 \fBCOLUMNS\fR, or the detected screen width if
2585 is not set\&. In addition, if
2589 format only affects screen output\&. If
2591 is nonzero then file and pipe output is wrapped to that width as well\&.
2596 Specifies the field separator to be used in
2598 output format\&. If the separator character appears in a field\*(Aqs value, that field is output within double quotes, following standard
2600 rules\&. The default is a comma\&.
2607 is specified it must be either
2610 off, which will enable or disable expanded mode, or
2613 is omitted the command toggles between the on and off settings\&. When expanded mode is enabled, query results are displayed in two columns, with the column name on the left and the data on the right\&. This mode is useful if the data wouldn\*(Aqt fit on the screen in the normal
2615 mode\&. In the auto setting, the expanded mode is used whenever the query output has more than one column and is wider than the screen; otherwise, the regular mode is used\&. The auto setting is only effective in the aligned and wrapped formats\&. In other formats, it always behaves as if the expanded mode is off\&.
2620 Specifies the field separator to be used in unaligned output format\&. That way one can create, for example, tab\-separated output, which other programs might prefer\&. To set a tab as field separator, type
2621 \epset fieldsep \*(Aq\et\*(Aq\&. The default field separator is
2628 Sets the field separator to use in unaligned output format to a zero byte\&.
2635 is specified it must be either
2639 which will enable or disable display of the table footer (the
2643 is omitted the command toggles footer display on or off\&.
2648 Sets the output format to one of
2657 wrapped\&. Unique abbreviations are allowed\&.
2660 format is the standard, human\-readable, nicely formatted text output; this is the default\&.
2663 format writes all columns of a row on one line, separated by the currently active field separator\&. This is useful for creating output that might be intended to be read in by other programs, for example, tab\-separated or comma\-separated format\&. However, the field separator character is not treated specially if it appears in a column\*(Aqs value; so
2665 format may be better suited for such purposes\&.
2670 writes column values separated by commas, applying the quoting rules described in
2671 \m[blue]\fBRFC 4180\fR\m[]\&. This output is compatible with the CSV format of the server\*(Aqs
2673 command\&. A header line with column names is generated unless the
2676 on\&. Titles and footers are not printed\&. Each row is terminated by the system\-dependent end\-of\-line character, which is typically a single newline (\en) for Unix\-like systems or a carriage return and newline sequence (\er\en) for Microsoft Windows\&. Field separator characters other than comma can be selected with
2677 \fB\epset csv_fieldsep\fR\&.
2682 but wraps wide data values across lines to make the output fit in the target column width\&. The target width is determined as described under the
2686 will not attempt to wrap column header titles; therefore,
2688 format behaves the same as
2690 if the total width needed for column headers exceeds the target\&.
2696 latex\-longtable, and
2698 formats put out tables that are intended to be included in documents using the respective mark\-up language\&. They are not complete documents! This might not be necessary in
2701 you must have a complete document wrapper\&. The
2718 Sets the border line drawing style to one of
2721 unicode\&. Unique abbreviations are allowed\&. (That would mean one letter is enough\&.) The default setting is
2722 ascii\&. This option only affects the
2731 characters\&. Newlines in data are shown using a
2733 symbol in the right\-hand margin\&. When the
2735 format wraps data from one line to the next without a newline character, a dot (\&.) is shown in the right\-hand margin of the first line, and again in the left\-hand margin of the following line\&.
2740 characters, using the formatting style used in
2742 8\&.4 and earlier\&. Newlines in data are shown using a
2744 symbol in place of the left\-hand column separator\&. When the data is wrapped from one line to the next without a newline character, a
2746 symbol is used in place of the left\-hand column separator\&.
2749 style uses Unicode box\-drawing characters\&. Newlines in data are shown using a carriage return symbol in the right\-hand margin\&. When the data is wrapped from one line to the next without a newline character, an ellipsis symbol is shown in the right\-hand margin of the first line, and again in the left\-hand margin of the following line\&.
2753 setting is greater than zero, the
2755 option also determines the characters with which the border lines are drawn\&. Plain
2757 characters work everywhere, but Unicode characters look nicer on displays that recognize them\&.
2762 Sets the string to be printed in place of a null value\&. The default is to print nothing, which can easily be mistaken for an empty string\&. For example, one might prefer
2763 \epset null \*(Aq(null)\*(Aq\&.
2770 is specified it must be either
2774 which will enable or disable display of a locale\-specific character to separate groups of digits to the left of the decimal marker\&. If
2776 is omitted the command toggles between regular and locale\-specific numeric output\&.
2781 Controls use of a pager program for query and
2783 help output\&. When the
2786 off, the pager program is not used\&. When the
2789 on, the pager is used when appropriate, i\&.e\&., when the output is to a terminal and will not fit on the screen\&. The
2791 option can also be set to
2792 always, which causes the pager to be used for all terminal output regardless of whether it fits on the screen\&.
2796 toggles pager use on and off\&.
2798 If the environment variable
2802 is set, output to be paged is piped to the specified program\&. Otherwise a platform\-dependent default program (such as
2807 command to execute a query repeatedly, the environment variable
2808 \fBPSQL_WATCH_PAGER\fR
2809 is used to find the pager program instead, on Unix systems\&. This is configured separately because it may confuse traditional pagers, but can be used to send output to tools that understand
2810 psql\*(Aqs output format (such as
2818 is set to a number greater than the page height, the pager program will not be called unless there are at least this many lines of output to show\&. The default setting is 0\&.
2823 Specifies the record (line) separator to use in unaligned output format\&. The default is a newline character\&.
2828 Sets the record separator to use in unaligned output format to a zero byte\&.
2835 format, this specifies attributes to be placed inside the
2837 tag\&. This could for example be
2840 bgcolor\&. Note that you probably don\*(Aqt want to specify
2842 here, as that is already taken care of by
2843 \epset border\&. If no
2845 is given, the table attributes are unset\&.
2849 format, this controls the proportional width of each column containing a left\-aligned data type\&. It is specified as a whitespace\-separated list of values, e\&.g\&.,
2850 \*(Aq0\&.2 0\&.2 0\&.6\*(Aq\&. Unspecified output columns use the last specified value\&.
2855 Sets the table title for any subsequently printed tables\&. This can be used to give your output descriptive tags\&. If no
2857 is given, the title is unset\&.
2864 is specified it must be either
2868 which will enable or disable tuples\-only mode\&. If
2870 is omitted the command toggles between regular and tuples\-only output\&. Regular output includes extra information such as column headers, titles, and various footers\&. In tuples\-only mode, only actual table data is shown\&.
2873 unicode_border_linestyle
2875 Sets the border drawing style for the
2877 line style to one of
2883 unicode_column_linestyle
2885 Sets the column drawing style for the
2887 line style to one of
2893 unicode_header_linestyle
2895 Sets the header drawing style for the
2897 line style to one of
2905 Sets the maximum width of the header for expanded output to one of
2907 (the default value),
2910 \fIinteger value\fR\&.
2912 full: the expanded header is not truncated, and will be as wide as the widest output line\&.
2914 column: truncate the header line to the width of the first column\&.
2916 page: truncate the header line to the terminal width\&.
2918 \fIinteger value\fR: specify the exact maximum width of the header line\&.
2921 Illustrations of how these different formats look can be seen in
2928 .nr an-no-space-flag 1
2935 There are various shortcut commands for
2952 program\&. In a script file, only execution of that script is terminated\&.
2955 \eqecho \fItext\fR [ \&.\&.\&. ]
2957 This command is identical to
2959 except that the output will be written to the query output channel, as set by
2965 Resets (clears) the query buffer\&.
2968 \erestrict \fIrestrict_key\fR
2970 Enter "restricted" mode with the provided key\&. In this mode, the only allowed meta\-command is
2971 \fB\eunrestrict\fR, to exit restricted mode\&. The key may contain only alphanumeric characters\&.
2973 This command is primarily intended for use in plain\-text dumps generated by
2976 pg_restore, but it may be useful elsewhere\&.
2979 \es [ \fIfilename\fR ]
2982 psql\*(Aqs command line history to
2983 \fIfilename\fR\&. If
2985 is omitted, the history is written to the standard output (using the pager if appropriate)\&. This command is not available if
2992 \eset [ \fIname\fR [ \fIvalue\fR [ \&.\&.\&. ] ] ]
2999 \fIvalue\fR, or if more than one value is given, to the concatenation of all of them\&. If only one argument is given, the variable is set to an empty\-string value\&. To unset a variable, use the
3004 without any arguments displays the names and values of all currently\-set
3008 Valid variable names can contain letters, digits, and underscores\&. See
3010 below for details\&. Variable names are case\-sensitive\&.
3012 Certain variables are special, in that they control
3013 psql\*(Aqs behavior or are automatically set to reflect connection state\&. These variables are documented in
3020 .nr an-no-space-flag 1
3027 This command is unrelated to the
3035 \esetenv \fIname\fR [ \fIvalue\fR ]
3037 Sets the environment variable
3040 \fIvalue\fR, or if the
3042 is not supplied, unsets the environment variable\&. Example:
3048 testdb=> \fB\esetenv PAGER less\fR
3049 testdb=> \fB\esetenv LESS \-imx4F\fR
3056 \esf[+] \fIfunction_description\fR
3058 This command fetches and shows the definition of the named function or procedure, in the form of a
3059 \fBCREATE OR REPLACE FUNCTION\fR
3061 \fBCREATE OR REPLACE PROCEDURE\fR
3062 command\&. The definition is printed to the current query output channel, as set by
3065 The target function can be specified by name alone, or by name and arguments, for example
3066 foo(integer, text)\&. The argument types must be given if there is more than one function of the same name\&.
3070 is appended to the command name, then the output lines are numbered, with the first line of the function body being line 1\&.
3072 Unlike most other meta\-commands, the entire remainder of the line is always taken to be the argument(s) of
3073 \fB\esf\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&.
3076 \esv[+] \fIview_name\fR
3078 This command fetches and shows the definition of the named view, in the form of a
3079 \fBCREATE OR REPLACE VIEW\fR
3080 command\&. The definition is printed to the current query output channel, as set by
3085 is appended to the command name, then the output lines are numbered from 1\&.
3087 Unlike most other meta\-commands, the entire remainder of the line is always taken to be the argument(s) of
3088 \fB\esv\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&.
3103 \egetresults [ \fInumber_results\fR ]
3105 This group of commands implements pipelining of SQL statements\&. A pipeline must begin with a
3106 \fB\estartpipeline\fR
3108 \fB\eendpipeline\fR\&. In between there may be any number of
3109 \fB\esyncpipeline\fR
3110 commands, which sends a
3112 without ending the ongoing pipeline and flushing the send buffer\&. In pipeline mode, statements are sent to the server without waiting for the results of previous statements\&. See
3116 All queries executed while a pipeline is ongoing use the extended query protocol\&. Queries are appended to the pipeline when ending with a semicolon\&. The meta\-commands
3122 can be used in an ongoing pipeline\&. While a pipeline is ongoing,
3124 will append the current query buffer to the pipeline\&. Other meta\-commands like
3129 are not allowed in pipeline mode\&.
3131 \fB\eflushrequest\fR
3132 appends a flush command to the pipeline, allowing to read results with
3134 without issuing a sync or ending the pipeline\&.
3136 will automatically push unsent data to the server\&.
3138 can be used to manually push unsent data\&.
3142 \fInumber_results\fR
3143 parameter\&. If provided, only the first
3144 \fInumber_results\fR
3145 pending results will be read\&. If not provided or
3146 0, all pending results are read\&.
3148 When pipeline mode is active, a dedicated prompt variable is available to report the pipeline status\&. See
3153 is not supported while in pipeline mode\&.
3162 SELECT * FROM pg_class;
3163 SELECT 1 \ebind \esendpipeline
3176 Toggles the display of output column name headings and row count footer\&. This command is equivalent to
3178 and is provided for convenience\&.
3181 \eT \fItable_options\fR
3183 Specifies attributes to be placed within the
3187 output format\&. This command is equivalent to
3188 \epset tableattr \fItable_options\fR\&.
3191 \etiming [ \fIon\fR | \fIoff\fR ]
3193 With a parameter, turns displaying of how long each SQL statement takes on or off\&. Without a parameter, toggles the display between on and off\&. The display is in milliseconds; intervals longer than 1 second are also shown in minutes:seconds format, with hours and days fields added if needed\&.
3196 \eunrestrict \fIrestrict_key\fR
3198 Exit "restricted" mode (i\&.e\&., where all other meta\-commands are blocked), provided the specified key matches the one given to
3200 when restricted mode was entered\&.
3202 This command is primarily intended for use in plain\-text dumps generated by
3205 pg_restore, but it may be useful elsewhere\&.
3210 Unsets (deletes) the
3215 Most variables that control
3216 psql\*(Aqs behavior cannot be unset; instead, an
3218 command is interpreted as setting them to their default values\&. See
3223 \ew or \ewrite \fIfilename\fR
3225 \ew or \ewrite |\fIcommand\fR
3227 Writes the current query buffer to the file
3229 or pipes it to the shell command
3230 \fIcommand\fR\&. If the current query buffer is empty, the most recently executed query is written instead\&.
3232 If the argument begins with
3233 |, then the entire remainder of the line is taken to be the
3235 to execute, and neither variable interpolation nor backquote expansion are performed in it\&. The rest of the line is simply passed literally to the shell\&.
3238 \ewarn \fItext\fR [ \&.\&.\&. ]
3240 This command is identical to
3242 except that the output will be written to
3243 psql\*(Aqs standard error channel, rather than standard output\&.
3246 \ewatch [ i[nterval]=\fIseconds\fR ] [ c[ount]=\fItimes\fR ] [ m[in_rows]=\fIrows\fR ] [ \fIseconds\fR ]
3248 Repeatedly execute the current query buffer (as
3250 does) until interrupted, or the query fails, or the execution count limit (if given) is reached, or the query no longer returns the minimum number of rows\&. Wait the specified number of seconds (default 2) between executions\&. The default wait can be changed with the variable
3251 \fIWATCH_INTERVAL\fR\&. For backwards compatibility,
3253 can be specified with or without an
3255 prefix\&. Each query result is displayed with a header that includes the
3257 string (if any), the time as of query start, and the delay interval\&.
3259 If the current query buffer is empty, the most recently sent query is re\-executed instead\&.
3262 \ex [ \fIon\fR | \fIoff\fR | \fIauto\fR ]
3264 Sets or toggles expanded table formatting mode\&. As such it is equivalent to
3268 \ez[Sx] [ \fIpattern\fR ]
3270 Lists tables, views and sequences with their associated access privileges\&. If a
3272 is specified, only tables, views and sequences whose names match the pattern are listed\&. By default only user\-created objects are shown; supply a pattern or the
3274 modifier to include system objects\&. If
3276 is appended to the command name, the results are displayed in expanded mode\&.
3278 This is an alias for
3280 (\(lqdisplay privileges\(rq)\&.
3283 \e! [ \fIcommand\fR ]
3285 With no argument, escapes to a sub\-shell;
3287 resumes when the sub\-shell exits\&. With an argument, executes the shell command
3290 Unlike most other meta\-commands, the entire remainder of the line is always taken to be the argument(s) of
3291 \fB\e!\fR, and neither variable interpolation nor backquote expansion are performed in the arguments\&. The rest of the line is simply passed literally to the shell\&.
3296 Shows help information\&. The optional
3298 parameter (defaulting to
3299 commands) selects which part of
3304 psql\*(Aqs backslash commands;
3306 describes the command\-line options that can be passed to
3311 configuration variables\&.
3316 Backslash\-semicolon is not a meta\-command in the same way as the preceding commands; rather, it simply causes a semicolon to be added to the query buffer without any further processing\&.
3320 will dispatch an SQL command to the server as soon as it reaches the command\-ending semicolon, even if more input remains on the current line\&. Thus for example entering
3326 select 1; select 2; select 3;
3332 will result in the three SQL commands being individually sent to the server, with each one\*(Aqs results being displayed before continuing to the next command\&. However, a semicolon entered as
3334 will not trigger command processing, so that the command before it and the one after are effectively combined and sent to the server in one request\&. So for example
3340 select 1\e; select 2\e; select 3;
3346 results in sending the three SQL commands to the server in a single request, when the non\-backslashed semicolon is reached\&. The server executes such a request as a single transaction, unless there are explicit
3347 \fBBEGIN\fR/\fBCOMMIT\fR
3348 commands included in the string to divide it into multiple transactions\&. (See
3350 for more details about how the server handles multi\-query strings\&.)
3354 .nr an-no-space-flag 1
3365 parameter to specify the object name(s) to be displayed\&. In the simplest case, a pattern is just the exact name of the object\&. The characters within a pattern are normally folded to lower case, just as in SQL names; for example,
3367 will display the table named
3368 foo\&. As in SQL names, placing double quotes around a pattern stops folding to lower case\&. Should you need to include an actual double quote character in a pattern, write it as a pair of double quotes within a double\-quote sequence; again this is in accord with the rules for SQL quoted identifiers\&. For example,
3370 will display the table named
3373 foo"bar)\&. Unlike the normal rules for SQL names, you can put double quotes around just part of a pattern, for instance
3375 will display the table named
3380 parameter is omitted completely, the
3382 commands display all objects that are visible in the current schema search path \(em this is equivalent to using
3384 as the pattern\&. (An object is said to be
3386 if its containing schema is in the search path and no object of the same kind and name appears earlier in the search path\&. This is equivalent to the statement that the object can be referenced by name without explicit schema qualification\&.) To see all objects in the database regardless of visibility, use
3392 matches any sequence of characters (including no characters) and
3394 matches any single character\&. (This notation is comparable to Unix shell file name patterns\&.) For example,
3396 displays tables whose names begin with
3397 int\&. But within double quotes,
3401 lose these special meanings and are just matched literally\&.
3403 A relation pattern that contains a dot (\&.) is interpreted as a schema name pattern followed by an object name pattern\&. For example,
3405 displays all tables whose table name includes
3407 that are in schemas whose schema name starts with
3408 foo\&. When no dot appears, then the pattern matches only objects that are visible in the current schema search path\&. Again, a dot within double quotes loses its special meaning and is matched literally\&. A relation pattern that contains two dots (\&.) is interpreted as a database name followed by a schema name pattern followed by an object name pattern\&. The database name portion will not be treated as a pattern and must match the name of the currently connected database, else an error will be raised\&.
3410 A schema pattern that contains a dot (\&.) is interpreted as a database name followed by a schema name pattern\&. For example,
3412 displays all schemas whose schema name includes
3413 foo\&. The database name portion will not be treated as a pattern and must match the name of the currently connected database, else an error will be raised\&.
3415 Advanced users can use regular\-expression notations such as character classes, for example
3417 to match any digit\&. All regular expression special characters work as specified in
3418 Section\ \&9.7.3, except for
3420 which is taken as a separator as mentioned above,
3422 which is translated to the regular\-expression notation
3425 which is translated to
3428 which is matched literally\&. You can emulate these pattern characters at need by writing
3439 is not needed as a regular\-expression character since the pattern must match the whole name, unlike the usual interpretation of regular expressions (in other words,
3441 is automatically appended to your pattern)\&. Write
3443 at the beginning and/or end if you don\*(Aqt wish the pattern to be anchored\&. Note that within double quotes, all regular expression special characters lose their special meanings and are matched literally\&. Also, the regular expression special characters are matched literally in operator name patterns (i\&.e\&., the argument of
3446 .SS "Advanced Features"
3449 .nr an-no-space-flag 1
3457 provides variable substitution features similar to common Unix command shells\&. Variables are simply name/value pairs, where the value can be any string of any length\&. The name must consist of letters (including non\-Latin letters), digits, and underscores\&.
3459 To set a variable, use the
3462 \fB\eset\fR\&. For example,
3468 testdb=> \fB\eset foo bar\fR
3477 bar\&. To retrieve the content of the variable, precede the name with a colon, for example:
3483 testdb=> \fB\eecho :foo\fR
3490 This works in both regular SQL commands and meta\-commands; there is more detail in
3491 SQL Interpolation, below\&.
3495 without a second argument, the variable is set to an empty\-string value\&. To unset (i\&.e\&., delete) a variable, use the command
3496 \fB\eunset\fR\&. To show the values of all variables, call
3498 without any argument\&.
3504 .nr an-no-space-flag 1
3514 are subject to the same substitution rules as with other commands\&. Thus you can construct interesting references such as
3515 \eset :foo \*(Aqsomething\*(Aq
3519 \(lqvariable variables\(rq
3524 fame, respectively\&. Unfortunately (or fortunately?), there is no way to do anything useful with these constructs\&. On the other hand,
3526 is a perfectly valid way to copy a variable\&.
3530 A number of these variables are treated specially by
3531 psql\&. They represent certain option settings that can be changed at run time by altering the value of the variable, or in some cases represent changeable state of
3532 psql\&. By convention, all specially treated variables\*(Aq names consist of all upper\-case ASCII letters (and possibly digits and underscores)\&. To ensure maximum compatibility in the future, avoid using such variable names for your own purposes\&.
3534 Variables that control
3535 psql\*(Aqs behavior generally cannot be unset or set to invalid values\&. An
3537 command is allowed but is interpreted as setting the variable to its default value\&. A
3539 command without a second argument is interpreted as setting the variable to
3540 on, for control variables that accept that value, and is rejected for others\&. Also, control variables that accept the values
3544 will also accept other common spellings of Boolean values, such as
3549 The specially treated variables are:
3555 (the default), each SQL command is automatically committed upon successful completion\&. To postpone commit in this mode, you must enter a
3558 \fBSTART TRANSACTION\fR
3561 or unset, SQL commands are not committed until you explicitly issue
3564 \fBEND\fR\&. The autocommit\-off mode works by issuing an implicit
3566 for you, just before any command that is not already in a transaction block and is not itself a
3568 or other transaction\-control command, nor a command that cannot be executed inside a transaction block (such as
3575 .nr an-no-space-flag 1
3582 In autocommit\-off mode, you must explicitly abandon any failed transaction by entering
3585 \fBROLLBACK\fR\&. Also keep in mind that if you exit the session without committing, your work will be lost\&.
3593 .nr an-no-space-flag 1
3600 The autocommit\-on mode is
3601 PostgreSQL\*(Aqs traditional behavior, but autocommit\-off is closer to the SQL spec\&. If you prefer autocommit\-off, you might wish to set it in the system\-wide
3610 \fICOMP_KEYWORD_CASE\fR
3612 Determines which letter case to use when completing an SQL key word\&. If set to
3615 upper, the completed word will be in lower or upper case, respectively\&. If set to
3619 (the default), the completed word will be in the case of the word already entered, but words being completed without anything entered will be in lower or upper case, respectively\&.
3624 The name of the database you are currently connected to\&. This is set every time you connect to a database (including program start\-up), but can be changed or unset\&.
3630 all, all nonempty input lines are printed to standard output as they are read\&. (This does not apply to lines read interactively\&.) To select this behavior on program start\-up, use the switch
3631 \fB\-a\fR\&. If set to
3634 prints each query to standard output as it is sent to the server\&. The switch to select this behavior is
3635 \fB\-e\fR\&. If set to
3636 errors, then only failed queries are displayed on standard error output\&. The switch for this behavior is
3637 \fB\-b\fR\&. If set to
3639 (the default), then no queries are displayed\&.
3644 When this variable is set to
3646 and a backslash command queries the database, the query is first shown\&. This feature helps you to study
3648 internals and provide similar functionality in your own programs\&. (To select this behavior on program start\-up, use the switch
3649 \fB\-E\fR\&.) If you set this variable to the value
3650 noexec, the queries are just shown but are not actually sent to the server and executed\&. The default value is
3656 The current client character set encoding\&. This is set every time you connect to a database (including program start\-up), and when you change the encoding with
3657 \eencoding, but it can be changed or unset\&.
3663 if the last SQL query failed,
3665 if it succeeded\&. See also
3671 If this variable is set to an integer value greater than zero, the results of
3673 queries are fetched and displayed in groups of that many rows, rather than the default behavior of collecting the entire result set before display\&. Therefore only a limited amount of memory is used, regardless of the size of the result set\&. Settings of 100 to 1000 are commonly used when enabling this feature\&. Keep in mind that when using this feature, a query might fail after having already displayed some rows\&.
3679 .nr an-no-space-flag 1
3686 Although you can use any output format with this feature, the default
3688 format tends to look bad because each group of
3690 rows will be formatted separately, leading to varying column widths across the row groups\&. The other output formats work better\&.
3697 If this variable is set to
3698 true, a table\*(Aqs access method details are not displayed\&. This is mainly useful for regression tests\&.
3701 \fIHIDE_TOAST_COMPRESSION\fR
3703 If this variable is set to
3704 true, column compression method details are not displayed\&. This is mainly useful for regression tests\&.
3709 If this variable is set to
3710 ignorespace, lines which begin with a space are not entered into the history list\&. If set to a value of
3711 ignoredups, lines matching the previous history line are not entered\&. A value of
3713 combines the two options\&. If set to
3715 (the default), all lines read in interactive mode are saved on the history list\&.
3721 .nr an-no-space-flag 1
3728 This feature was shamelessly plagiarized from
3736 The file name that will be used to store the history list\&. If unset, the file name is taken from the
3738 environment variable\&. If that is not set either, the default is
3739 ~/\&.psql_history, or
3740 %APPDATA%\epostgresql\epsql_history
3741 on Windows\&. For example, putting:
3747 \eset HISTFILE ~/\&.psql_history\-:DBNAME
3757 to maintain a separate history for each database\&.
3763 .nr an-no-space-flag 1
3770 This feature was shamelessly plagiarized from
3778 The maximum number of commands to store in the command history (default 500)\&. If set to a negative value, no limit is applied\&.
3784 .nr an-no-space-flag 1
3791 This feature was shamelessly plagiarized from
3799 The database server host you are currently connected to\&. This is set every time you connect to a database (including program start\-up), but can be changed or unset\&.
3804 If set to 1 or less, sending an
3807 Control+D) to an interactive session of
3809 will terminate the application\&. If set to a larger numeric value, that many consecutive
3811 characters must be typed to make an interactive session terminate\&. If the variable is set to a non\-numeric value, it is interpreted as 10\&. The default is 0\&.
3817 .nr an-no-space-flag 1
3824 This feature was shamelessly plagiarized from
3832 The value of the last affected OID, as returned from an
3836 command\&. This variable is only guaranteed to be valid until after the result of the next
3838 command has been displayed\&.
3840 servers since version 12 do not support OID system columns anymore, thus LASTOID will always be 0 following
3842 when targeting such servers\&.
3845 \fILAST_ERROR_MESSAGE\fR
3847 \fILAST_ERROR_SQLSTATE\fR
3849 The primary error message and associated SQLSTATE code for the most recent failed query in the current
3851 session, or an empty string and
3853 if no error has occurred in the current session\&.
3856 \fION_ERROR_ROLLBACK\fR
3859 on, if a statement in a transaction block generates an error, the error is ignored and the transaction continues\&. When set to
3860 interactive, such errors are only ignored in interactive sessions, and not when reading script files\&. When set to
3862 (the default), a statement in a transaction block that generates an error aborts the entire transaction\&. The error rollback mode works by issuing an implicit
3864 for you, just before each command that is in a transaction block, and then rolling back to the savepoint if the command fails\&.
3869 By default, command processing continues after an error\&. When this variable is set to
3870 on, processing will instead stop immediately\&. In interactive mode,
3872 will return to the command prompt; otherwise,
3874 will exit, returning error code 3 to distinguish this case from fatal error conditions, which are reported using error code 1\&. In either case, any currently running scripts (the top\-level script, if any, and any other scripts which it may have in invoked) will be terminated immediately\&. If the top\-level command string contained multiple SQL commands, processing will stop with the current command\&.
3877 \fIPIPELINE_COMMAND_COUNT\fR
3879 The number of commands queued in an ongoing pipeline\&.
3882 \fIPIPELINE_RESULT_COUNT\fR
3884 The number of commands of an ongoing pipeline that were followed by either a
3885 \fB\eflushrequest\fR
3887 \fB\esyncpipeline\fR, forcing the server to send the results\&. These results can be retrieved with
3888 \fB\egetresults\fR\&.
3891 \fIPIPELINE_SYNC_COUNT\fR
3893 The number of sync messages queued in an ongoing pipeline\&.
3898 The database server port to which you are currently connected\&. This is set every time you connect to a database (including program start\-up), but can be changed or unset\&.
3907 These specify what the prompts
3909 issues should look like\&. See
3916 Setting this variable to
3918 is equivalent to the command line option
3919 \fB\-q\fR\&. It is probably not too useful in interactive mode\&.
3924 The number of rows returned or affected by the last SQL query, or 0 if the query failed or did not report a row count\&.
3927 \fISERVER_VERSION_NAME\fR
3929 \fISERVER_VERSION_NUM\fR
3931 The server\*(Aqs version number as a string, for example
3935 11beta1, and in numeric form, for example
3938 100001\&. These are set every time you connect to a database (including program start\-up), but can be changed or unset\&.
3943 The service name, if applicable\&.
3949 if the last shell command failed,
3951 if it succeeded\&. This applies to shell commands invoked via the
3957 meta\-commands, as well as backquote (`) expansion\&. Note that for
3958 \eo, this variable is updated when the output pipe is closed by the next
3961 \fISHELL_EXIT_CODE\fR\&.
3964 \fISHELL_EXIT_CODE\fR
3966 The exit status returned by the last shell command\&. 0\(en127 represent program exit codes, 128\(en255 indicate termination by a signal, and \-1 indicates failure to launch a program or to collect its exit status\&. This applies to shell commands invoked via the
3972 meta\-commands, as well as backquote (`) expansion\&. Note that for
3973 \eo, this variable is updated when the output pipe is closed by the next
3976 \fISHELL_ERROR\fR\&.
3979 \fISHOW_ALL_RESULTS\fR
3981 When this variable is set to
3982 off, only the last result of a combined query (\e;) is shown instead of all of them\&. The default is
3983 on\&. The off behavior is for compatibility with older versions of
3989 This variable can be set to the values
3995 fields are displayed in messages from the server\&. The default is
3997 (meaning that context will be shown in error messages, but not in notice or warning messages)\&. This setting has no effect when
4002 sqlstate\&. (See also
4003 \fB\eerrverbose\fR, for use when you want a verbose version of the error you just got\&.)
4008 Setting this variable to
4010 is equivalent to the command line option
4016 Setting this variable to
4018 is equivalent to the command line option
4025 Appendix\ \&A) associated with the last SQL query\*(Aqs failure, or
4032 The database user you are currently connected as\&. This is set every time you connect to a database (including program start\-up), but can be changed or unset\&.
4037 This variable can be set to the values
4042 to control the verbosity of error reports\&. (See also
4043 \fB\eerrverbose\fR, for use when you want a verbose version of the error you just got\&.)
4052 These variables are set at program start\-up to reflect
4053 psql\*(Aqs version, respectively as a verbose string, a short string (e\&.g\&.,
4056 11beta1), and a number (e\&.g\&.,
4059 100001)\&. They can be changed or unset\&.
4062 \fIWATCH_INTERVAL\fR
4064 This variable sets the default interval, in seconds, which
4066 waits between executing the query\&. The default is 2 seconds\&. Specifying an interval in the command overrides this variable\&.
4071 .nr an-no-space-flag 1
4075 \fBSQL Interpolation\fR
4080 variables is that you can substitute (\(lqinterpolate\(rq) them into regular
4082 statements, as well as the arguments of meta\-commands\&. Furthermore,
4084 provides facilities for ensuring that variable values used as SQL literals and identifiers are properly quoted\&. The syntax for interpolating a value without any quoting is to prepend the variable name with a colon (:)\&. For example,
4090 testdb=> \fB\eset foo \*(Aqmy_table\*(Aq\fR
4091 testdb=> \fBSELECT * FROM :foo;\fR
4097 would query the table
4098 my_table\&. Note that this may be unsafe: the value of the variable is copied literally, so it can contain unbalanced quotes, or even backslash commands\&. You must make sure that it makes sense where you put it\&.
4100 When a value is to be used as an SQL literal or identifier, it is safest to arrange for it to be quoted\&. To quote the value of a variable as an SQL literal, write a colon followed by the variable name in single quotes\&. To quote the value as an SQL identifier, write a colon followed by the variable name in double quotes\&. These constructs deal correctly with quotes and other special characters embedded within the variable value\&. The previous example would be more safely written this way:
4106 testdb=> \fB\eset foo \*(Aqmy_table\*(Aq\fR
4107 testdb=> \fBSELECT * FROM :"foo";\fR
4113 Variable interpolation will not be performed within quoted
4115 literals and identifiers\&. Therefore, a construction such as
4117 doesn\*(Aqt work to produce a quoted literal from a variable\*(Aqs value (and it would be unsafe if it did work, since it wouldn\*(Aqt correctly handle quotes embedded in the value)\&.
4119 One example use of this mechanism is to copy the contents of a file into a table column\&. First load the file into a variable and then interpolate the variable\*(Aqs value as a quoted string:
4125 testdb=> \fB\eset content `cat my_file\&.txt`\fR
4126 testdb=> \fBINSERT INTO my_table VALUES (:\*(Aqcontent\*(Aq);\fR
4132 (Note that this still won\*(Aqt work if
4134 contains NUL bytes\&.
4136 does not support embedded NUL bytes in variable values\&.)
4138 Since colons can legally appear in SQL commands, an apparent attempt at interpolation (that is,
4141 :"name") is not replaced unless the named variable is currently set\&. In any case, you can escape a colon with a backslash to protect it from substitution\&.
4145 special syntax returns TRUE or FALSE depending on whether the variable exists or not, and is thus always substituted, unless the colon is backslash\-escaped\&.
4147 The colon syntax for variables is standard
4149 for embedded query languages, such as
4150 ECPG\&. The colon syntaxes for array slices and type casts are
4152 extensions, which can sometimes conflict with the standard usage\&. The colon\-quote syntax for escaping a variable\*(Aqs value as an SQL literal or identifier is a
4158 .nr an-no-space-flag 1
4167 issues can be customized to your preference\&. The three variables
4171 contain strings and special escape sequences that describe the appearance of the prompt\&. Prompt 1 is the normal prompt that is issued when
4173 requests a new command\&. Prompt 2 is issued when more input is expected during command entry, for example because the command was not terminated with a semicolon or a quote was not closed\&. Prompt 3 is issued when you are running an
4175 \fBCOPY FROM STDIN\fR
4176 command and you need to type in a row value on the terminal\&.
4178 The value of the selected prompt variable is printed literally, except where a percent sign (%) is encountered\&. Depending on the next character, certain other text is substituted instead\&. Defined substitutions are:
4182 The full host name (with domain name) of the database server, or
4184 if the connection is over a Unix domain socket, or
4185 [local:\fI/dir/name\fR], if the Unix domain socket is not at the compiled in default location\&.
4190 The host name of the database server, truncated at the first dot, or
4192 if the connection is over a Unix domain socket\&.
4197 The port number at which the database server is listening\&.
4202 The database session user name\&. (The expansion of this value might change during a database session as the result of the command
4203 \fBSET SESSION AUTHORIZATION\fR\&.)
4208 The name of the service\&.
4213 The name of the current database\&.
4219 %/, but the output is
4221 (tilde) if the database is your default database\&.
4226 If the session user is a database superuser, then a
4228 >\&. (The expansion of this value might change during a database session as the result of the command
4229 \fBSET SESSION AUTHORIZATION\fR\&.)
4234 The process ID of the backend currently connected to\&.
4241 when not in a pipeline,
4243 when in an ongoing pipeline or
4245 when in an aborted pipeline\&.
4250 In prompt 1 normally
4253 if the session is in an inactive branch of a conditional block, or
4255 if in single\-line mode, or
4257 if the session is disconnected from the database (which can happen if
4259 fails)\&. In prompt 2
4261 is replaced by a character that depends on why
4265 if the command simply wasn\*(Aqt terminated yet, but
4267 if there is an unfinished
4269 comment, a single quote if there is an unfinished quoted string, a double quote if there is an unfinished quoted identifier, a dollar sign if there is an unfinished dollar\-quoted string, or
4271 if there is an unmatched left parenthesis\&. In prompt 3
4273 doesn\*(Aqt produce anything\&.
4278 Transaction status: an empty string when not in a transaction block, or
4280 when in a transaction block, or
4282 when in a failed transaction block, or
4284 when the transaction state is indeterminate (for example, because there is no connection)\&.
4289 The line number inside the current statement, starting from
4295 The character with the indicated octal code is substituted\&.
4304 Variables, above, for details\&.
4310 \fIcommand\fR, similar to ordinary
4317 Prompts can contain terminal control characters which, for example, change the color, background, or style of the prompt text, or change the title of the terminal window\&. In order for the line editing features of
4319 to work properly, these non\-printing control characters must be designated as invisible by surrounding them with
4322 %]\&. Multiple pairs of these can occur within the prompt\&. For example:
4328 testdb=> \eset PROMPT1 \*(Aq%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# \*(Aq
4334 results in a boldfaced (1;) yellow\-on\-black (33;40) prompt on VT100\-compatible, color\-capable terminals\&.
4339 Whitespace of the same width as the most recent output of
4340 \fIPROMPT1\fR\&. This can be used as a
4342 setting, so that multi\-line statements are aligned with the first line, but there is no visible secondary prompt\&.
4344 To insert a percent sign into your prompt, write
4345 %%\&. The default prompts are
4347 for prompts 1 and 2, and
4355 .nr an-no-space-flag 1
4363 This feature was shamelessly plagiarized from
4370 .nr an-no-space-flag 1
4374 \fBCommand-Line Editing\fR
4382 library, if available, for convenient line editing and retrieval\&. The command history is automatically saved when
4384 exits and is reloaded when
4386 starts up\&. Type up\-arrow or control\-P to retrieve previous lines\&.
4388 You can also use tab completion to fill in partially\-typed keywords and SQL object names in many (by no means all) contexts\&. For example, at the start of a command, typing
4390 and pressing TAB will fill in
4391 insert into\&. Then, typing a few characters of a table or schema name and pressing
4393 will fill in the unfinished name, or offer a menu of possible completions when there\*(Aqs more than one\&. (Depending on the library in use, you may need to press
4395 more than once to get a menu\&.)
4397 Tab completion for SQL object names requires sending queries to the server to find possible matches\&. In some contexts this can interfere with other operations\&. For example, after
4399 it will be too late to issue
4400 \fBSET TRANSACTION ISOLATION LEVEL\fR
4401 if a tab\-completion query is issued in between\&. If you do not want tab completion at all, you can turn it off permanently by putting this in a file named
4403 in your home directory:
4410 set disable\-completion on
4421 feature\&. Read its documentation for further details\&.)
4425 (\fB\-\-no\-readline\fR) command line option can also be useful to disable use of
4428 psql\&. This prevents tab completion, use or recording of command line history, and editing of multi\-line commands\&. It is particularly useful when you need to copy\-and\-paste text that contains
4438 is zero, controls the width for the
4440 format and width for determining if wide output requires the pager or should be switched to the vertical format in expanded auto mode\&.
4451 Default connection parameters (see
4452 Section\ \&32.15)\&.
4457 Specifies whether to use color in diagnostic messages\&. Possible values are
4474 commands\&. These variables are examined in the order listed; the first that is set is used\&. If none of them is set, the default is to use
4478 on Windows systems\&.
4481 \fBPSQL_EDITOR_LINENUMBER_ARG\fR
4487 is used with a line number argument, this variable specifies the command\-line argument used to pass the starting line number to the user\*(Aqs editor\&. For editors such as
4490 vi, this is a plus sign\&. Include a trailing space in the value of the variable if there needs to be space between the option name and the line number\&. Examples:
4496 PSQL_EDITOR_LINENUMBER_ARG=\*(Aq+\*(Aq
4497 PSQL_EDITOR_LINENUMBER_ARG=\*(Aq\-\-line \*(Aq
4505 on Unix systems (corresponding to the default editor
4506 vi, and useful for many other common editors); but there is no default on Windows systems\&.
4511 Alternative location for the command history file\&. Tilde (~) expansion is performed\&.
4518 If a query\*(Aqs results do not fit on the screen, they are piped through this command\&. Typical values are
4521 less\&. Use of the pager can be disabled by setting
4525 to an empty string, or by adjusting the pager\-related options of the
4527 command\&. These variables are examined in the order listed; the first that is set is used\&. If neither of them is set, the default is to use
4529 on most platforms, but
4534 \fBPSQL_WATCH_PAGER\fR
4536 When a query is executed repeatedly with the
4538 command, a pager is not used by default\&. This behavior can be changed by setting
4539 \fBPSQL_WATCH_PAGER\fR
4540 to a pager command, on Unix systems\&. The
4544 but available in many open source software distributions) can display the output of
4546 if started with the option
4552 Alternative location of the user\*(Aqs
4554 file\&. Tilde (~) expansion is performed\&.
4559 Command executed by the
4566 Directory for storing temporary files\&. The default is
4570 This utility, like most other
4572 utilities, also uses the environment variables supported by
4575 Section\ \&32.15)\&.
4578 psqlrc and ~/\&.psqlrc
4580 Unless it is passed an
4584 attempts to read and execute commands from the system\-wide startup file (psqlrc) and then the user\*(Aqs personal startup file (~/\&.psqlrc), after connecting to the database but before accepting normal commands\&. These files can be used to set up the client and/or the server to taste, typically with
4590 The system\-wide startup file is named
4591 psqlrc\&. By default it is sought in the installation\*(Aqs
4592 \(lqsystem configuration\(rq
4593 directory, which is most reliably identified by running
4594 pg_config \-\-sysconfdir\&. Typically this directory will be
4596 relative to the directory containing the
4598 executables\&. The directory to look in can be set explicitly via the
4600 environment variable\&.
4602 The user\*(Aqs personal startup file is named
4604 and is sought in the invoking user\*(Aqs home directory\&. On Windows the personal startup file is instead named
4605 %APPDATA%\epostgresql\epsqlrc\&.conf\&. In either case, this default file path can be overridden by setting the
4607 environment variable\&.
4609 Both the system\-wide startup file and the user\*(Aqs personal startup file can be made
4610 psql\-version\-specific by appending a dash and the
4612 major or minor release identifier to the file name, for example
4615 ~/\&.psqlrc\-18\&.0\&. The most specific version\-matching file will be read in preference to a non\-version\-specific file\&. These version suffixes are added after determining the file path as explained above\&.
4620 The command\-line history is stored in the file
4621 ~/\&.psql_history, or
4622 %APPDATA%\epostgresql\epsql_history
4625 The location of the history file can be set explicitly via the
4630 environment variable\&.
4636 \h'-04'\(bu\h'+03'\c
4643 works best with servers of the same or an older major version\&. Backslash commands are particularly likely to fail if the server is of a newer version than
4645 itself\&. However, backslash commands of the
4647 family should work with servers of versions back to 9\&.2, though not necessarily with servers newer than
4649 itself\&. The general functionality of running SQL commands and displaying query results should also work with servers of a newer major version, but this cannot be guaranteed in all cases\&.
4653 to connect to several servers of different major versions, it is recommended that you use the newest version of
4654 psql\&. Alternatively, you can keep around a copy of
4656 from each major version and be sure to use the version that matches the respective server\&. But in practice, this additional complication should not be necessary\&.
4661 \h'-04'\(bu\h'+03'\c
4673 (\fB\-\-no\-psqlrc\fR); this is no longer the case\&.
4678 \h'-04'\(bu\h'+03'\c
4688 allowed the first argument of a single\-letter backslash command to start directly after the command, without intervening whitespace\&. Now, some whitespace is required\&.
4690 .SH "NOTES FOR WINDOWS USERS"
4694 \(lqconsole application\(rq\&. Since the Windows console windows use a different encoding than the rest of the system, you must take special care when using 8\-bit characters within
4697 detects a problematic console code page, it will warn you at startup\&. To change the console code page, two things are necessary:
4701 \h'-04'\(bu\h'+03'\c
4707 Set the code page by entering
4708 \fBcmd\&.exe /c chcp 1252\fR\&. (1252 is a code page that is appropriate for German; replace it with your value\&.) If you are using Cygwin, you can put this command in
4714 \h'-04'\(bu\h'+03'\c
4720 Set the console font to
4721 Lucida Console, because the raster font does not work with the ANSI code page\&.
4725 The first example shows how to spread a command over several lines of input\&. Notice the changing prompt:
4731 testdb=> \fBCREATE TABLE my_table (\fR
4732 testdb(> \fB first integer not null default 0,\fR
4733 testdb(> \fB second text)\fR
4741 Now look at the table definition again:
4747 testdb=> \fB\ed my_table\fR
4748 Table "public\&.my_table"
4749 Column | Type | Collation | Nullable | Default
4750 \-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-
4751 first | integer | | not null | 0
4758 Now we change the prompt to something more interesting:
4764 testdb=> \fB\eset PROMPT1 \*(Aq%n@%m %~%R%# \*(Aq\fR
4765 peter@localhost testdb=>
4771 Let\*(Aqs assume you have filled the table with data and want to take a look at it:
4777 peter@localhost testdb=> SELECT * FROM my_table;
4779 \-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-
4790 You can display tables in different ways by using the
4798 peter@localhost testdb=> \fB\epset border 2\fR
4799 Border style is 2\&.
4800 peter@localhost testdb=> \fBSELECT * FROM my_table;\fR
4801 +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+
4803 +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+
4808 +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+
4811 peter@localhost testdb=> \fB\epset border 0\fR
4812 Border style is 0\&.
4813 peter@localhost testdb=> \fBSELECT * FROM my_table;\fR
4815 \-\-\-\-\- \-\-\-\-\-\-
4822 peter@localhost testdb=> \fB\epset border 1\fR
4823 Border style is 1\&.
4824 peter@localhost testdb=> \fB\epset format csv\fR
4825 Output format is csv\&.
4826 peter@localhost testdb=> \fB\epset tuples_only\fR
4827 Tuples only is on\&.
4828 peter@localhost testdb=> \fBSELECT second, first FROM my_table;\fR
4833 peter@localhost testdb=> \fB\epset format unaligned\fR
4834 Output format is unaligned\&.
4835 peter@localhost testdb=> \fB\epset fieldsep \*(Aq\et\*(Aq\fR
4836 Field separator is " "\&.
4837 peter@localhost testdb=> \fBSELECT second, first FROM my_table;\fR
4847 Alternatively, use the short commands:
4853 peter@localhost testdb=> \fB\ea \et \ex\fR
4854 Output format is aligned\&.
4855 Tuples only is off\&.
4856 Expanded display is on\&.
4857 peter@localhost testdb=> \fBSELECT * FROM my_table;\fR
4875 Also, these output format options can be set for just one query by using
4882 peter@localhost testdb=> \fBSELECT * FROM my_table\fR
4883 peter@localhost testdb\-> \fB\eg (format=aligned tuples_only=off expanded=on)\fR
4901 Here is an example of using the
4903 command to find only functions with names matching
4905 and whose second argument is of type
4912 testdb=> \fB\edf int*pl * bigint\fR
4914 Schema | Name | Result data type | Argument data types | Type
4915 \-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-
4916 pg_catalog | int28pl | bigint | smallint, bigint | func
4917 pg_catalog | int48pl | bigint | integer, bigint | func
4918 pg_catalog | int8pl | bigint | bigint, bigint | func
4927 option is used to display additional information about one of these functions, and
4929 is used to display the results in expanded mode:
4935 testdb=> \fB\edf+x int*pl integer bigint\fR
4937 \-[ RECORD 1 ]\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
4940 Result data type | bigint
4941 Argument data types | integer, bigint
4943 Volatility | immutable
4950 Internal name | int48pl
4951 Description | implementation of + operator
4957 When suitable, query results can be shown in a crosstab representation with the
4958 \fB\ecrosstabview\fR
4965 testdb=> \fBSELECT first, second, first > 2 AS gt2 FROM my_table;\fR
4966 first | second | gt2
4967 \-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+\-\-\-\-\-
4974 testdb=> \fB\ecrosstabview first second\fR
4975 first | one | two | three | four
4976 \-\-\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-\-\-+\-\-\-\-\-\-
4987 This second example shows a multiplication table with rows sorted in reverse numerical order and columns with an independent, ascending numerical order\&.
4993 testdb=> \fBSELECT t1\&.first as "A", t2\&.first+100 AS "B", t1\&.first*(t2\&.first+100) as "AxB",\fR
4994 testdb\-> \fBrow_number() over(order by t2\&.first) AS ord\fR
4995 testdb\-> \fBFROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC\fR
4996 testdb\-> \fB\ecrosstabview "A" "B" "AxB" ord\fR
4997 A | 101 | 102 | 103 | 104
4998 \-\-\-+\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-
4999 4 | 404 | 408 | 412 | 416
5000 3 | 303 | 306 | 309 | 312
5001 2 | 202 | 204 | 206 | 208
5002 1 | 101 | 102 | 103 | 104