]> begriffs open source - ai-pg/blob - full-docs/man1/psql.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / psql.1
1 '\" t
2 .\"     Title: psql
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 psql \- PostgreSQL interactive terminal
32 .SH "SYNOPSIS"
33 .HP \w'\fBpsql\fR\ 'u
34 \fBpsql\fR [\fIoption\fR...] [\fIdbname\fR\ [\fIusername\fR]]
35 .SH "DESCRIPTION"
36 .PP
37 psql
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,
41 psql
42 provides a number of meta\-commands and various shell\-like features to facilitate writing scripts and automating a wide variety of tasks\&.
43 .SH "OPTIONS"
44 .PP
45 \fB\-a\fR
46 .br
47 \fB\-\-echo\-all\fR
48 .RS 4
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
50 \fIECHO\fR
51 to
52 all\&.
53 .RE
54 .PP
55 \fB\-A\fR
56 .br
57 \fB\-\-no\-align\fR
58 .RS 4
59 Switches to unaligned output mode\&. (The default output mode is
60 aligned\&.) This is equivalent to
61 \fB\epset format unaligned\fR\&.
62 .RE
63 .PP
64 \fB\-b\fR
65 .br
66 \fB\-\-echo\-errors\fR
67 .RS 4
68 Print failed SQL commands to standard error output\&. This is equivalent to setting the variable
69 \fIECHO\fR
70 to
71 errors\&.
72 .RE
73 .PP
74 \fB\-c \fR\fB\fIcommand\fR\fR
75 .br
76 \fB\-\-command=\fR\fB\fIcommand\fR\fR
77 .RS 4
78 Specifies that
79 psql
80 is to execute the given command string,
81 \fIcommand\fR\&. This option can be repeated and combined in any order with the
82 \fB\-f\fR
83 option\&. When either
84 \fB\-c\fR
85 or
86 \fB\-f\fR
87 is specified,
88 psql
89 does not read commands from standard input; instead it terminates after processing all the
90 \fB\-c\fR
91 and
92 \fB\-f\fR
93 options in sequence\&.
94 .sp
95 \fIcommand\fR
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
98 SQL
99 and
100 psql
101 meta\-commands within a
102 \fB\-c\fR
103 option\&. To achieve that, you could use repeated
104 \fB\-c\fR
105 options or pipe the string into
106 psql, for example:
107 .sp
108 .if n \{\
109 .RS 4
110 .\}
111 .nf
112 psql \-c \*(Aq\ex\*(Aq \-c \*(AqSELECT * FROM foo;\*(Aq
113 .fi
114 .if n \{\
115 .RE
116 .\}
117 .sp
118 or
119 .sp
120 .if n \{\
121 .RS 4
122 .\}
123 .nf
124 echo \*(Aq\ex \e\e SELECT * FROM foo;\*(Aq | psql
125 .fi
126 .if n \{\
127 .RE
128 .\}
129 .sp
130 (\e\e
131 is the separator meta\-command\&.)
132 .sp
133 Each
134 SQL
135 command string passed to
136 \fB\-c\fR
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
138 SQL
139 commands, unless there are explicit
140 \fBBEGIN\fR/\fBCOMMIT\fR
141 commands included in the string to divide it into multiple transactions\&. (See
142 Section\ \&54.2.2.1
143 for more details about how the server handles multi\-query strings\&.)
144 .sp
145 If having several commands executed in one transaction is not desired, use repeated
146 \fB\-c\fR
147 commands or feed multiple commands to
148 psql\*(Aqs standard input, either using
149 echo
150 as illustrated above, or via a shell here\-document, for example:
151 .sp
152 .if n \{\
153 .RS 4
154 .\}
155 .nf
156 psql <<EOF
157 \ex
158 SELECT * FROM foo;
159 EOF
160 .fi
161 .if n \{\
162 .RE
163 .\}
164 .RE
165 .PP
166 \fB\-\-csv\fR
167 .RS 4
168 Switches to
169 CSV
170 (Comma\-Separated Values) output mode\&. This is equivalent to
171 \fB\epset format csv\fR\&.
172 .RE
173 .PP
174 \fB\-d \fR\fB\fIdbname\fR\fR
175 .br
176 \fB\-\-dbname=\fR\fB\fIdbname\fR\fR
177 .RS 4
178 Specifies the name of the database to connect to\&. This is equivalent to specifying
179 \fIdbname\fR
180 as the first non\-option argument on the command line\&. The
181 \fIdbname\fR
182 can be a
183 connection string\&. If so, connection string parameters will override any conflicting command line options\&.
184 .RE
185 .PP
186 \fB\-e\fR
187 .br
188 \fB\-\-echo\-queries\fR
189 .RS 4
190 Copy all SQL commands sent to the server to standard output as well\&. This is equivalent to setting the variable
191 \fIECHO\fR
192 to
193 queries\&.
194 .RE
195 .PP
196 \fB\-E\fR
197 .br
198 \fB\-\-echo\-hidden\fR
199 .RS 4
200 Echo the actual queries generated by
201 \fB\ed\fR
202 and other backslash commands\&. You can use this to study
203 psql\*(Aqs internal operations\&. This is equivalent to setting the variable
204 \fIECHO_HIDDEN\fR
205 to
206 on\&.
207 .RE
208 .PP
209 \fB\-f \fR\fB\fIfilename\fR\fR
210 .br
211 \fB\-\-file=\fR\fB\fIfilename\fR\fR
212 .RS 4
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
215 \fB\-c\fR
216 option\&. When either
217 \fB\-c\fR
218 or
219 \fB\-f\fR
220 is specified,
221 psql
222 does not read commands from standard input; instead it terminates after processing all the
223 \fB\-c\fR
224 and
225 \fB\-f\fR
226 options in sequence\&. Except for that, this option is largely equivalent to the meta\-command
227 \fB\ei\fR\&.
228 .sp
229 If
230 \fIfilename\fR
231 is
232 \-
233 (hyphen), then standard input is read until an EOF indication or
234 \fB\eq\fR
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
236 \fB\-n\fR
237 had been specified)\&.
238 .sp
239 Using this option is subtly different from writing
240 psql < \fIfilename\fR\&. In general, both will do what you expect, but using
241 \-f
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\&.
243 .RE
244 .PP
245 \fB\-F \fR\fB\fIseparator\fR\fR
246 .br
247 \fB\-\-field\-separator=\fR\fB\fIseparator\fR\fR
248 .RS 4
249 Use
250 \fIseparator\fR
251 as the field separator for unaligned output\&. This is equivalent to
252 \fB\epset fieldsep\fR
253 or
254 \fB\ef\fR\&.
255 .RE
256 .PP
257 \fB\-h \fR\fB\fIhostname\fR\fR
258 .br
259 \fB\-\-host=\fR\fB\fIhostname\fR\fR
260 .RS 4
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\&.
262 .RE
263 .PP
264 \fB\-H\fR
265 .br
266 \fB\-\-html\fR
267 .RS 4
268 Switches to
269 HTML
270 output mode\&. This is equivalent to
271 \fB\epset format html\fR
272 or the
273 \fB\eH\fR
274 command\&.
275 .RE
276 .PP
277 \fB\-l\fR
278 .br
279 \fB\-\-list\fR
280 .RS 4
281 List all available databases, then exit\&. Other non\-connection options are ignored\&. This is similar to the meta\-command
282 \fB\elist\fR\&.
283 .sp
284 When this option is used,
285 psql
286 will connect to the database
287 postgres, unless a different database is named on the command line (option
288 \fB\-d\fR
289 or non\-option argument, possibly via a service entry, but not via an environment variable)\&.
290 .RE
291 .PP
292 \fB\-L \fR\fB\fIfilename\fR\fR
293 .br
294 \fB\-\-log\-file=\fR\fB\fIfilename\fR\fR
295 .RS 4
296 Write all query output into file
297 \fIfilename\fR, in addition to the normal output destination\&.
298 .RE
299 .PP
300 \fB\-n\fR
301 .br
302 \fB\-\-no\-readline\fR
303 .RS 4
304 Do not use
305 Readline
306 for line editing and do not use the command history (see
307 the section called \(lqCommand\-Line Editing\(rq
308 below)\&.
309 .RE
310 .PP
311 \fB\-o \fR\fB\fIfilename\fR\fR
312 .br
313 \fB\-\-output=\fR\fB\fIfilename\fR\fR
314 .RS 4
315 Put all query output into file
316 \fIfilename\fR\&. This is equivalent to the command
317 \fB\eo\fR\&.
318 .RE
319 .PP
320 \fB\-p \fR\fB\fIport\fR\fR
321 .br
322 \fB\-\-port=\fR\fB\fIport\fR\fR
323 .RS 4
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
325 \fBPGPORT\fR
326 environment variable or, if not set, to the port specified at compile time, usually 5432\&.
327 .RE
328 .PP
329 \fB\-P \fR\fB\fIassignment\fR\fR
330 .br
331 \fB\-\-pset=\fR\fB\fIassignment\fR\fR
332 .RS 4
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
336 \-P format=latex\&.
337 .RE
338 .PP
339 \fB\-q\fR
340 .br
341 \fB\-\-quiet\fR
342 .RS 4
343 Specifies that
344 psql
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
346 \fB\-c\fR
347 option\&. This is equivalent to setting the variable
348 \fIQUIET\fR
349 to
350 on\&.
351 .RE
352 .PP
353 \fB\-R \fR\fB\fIseparator\fR\fR
354 .br
355 \fB\-\-record\-separator=\fR\fB\fIseparator\fR\fR
356 .RS 4
357 Use
358 \fIseparator\fR
359 as the record separator for unaligned output\&. This is equivalent to
360 \fB\epset recordsep\fR\&.
361 .RE
362 .PP
363 \fB\-s\fR
364 .br
365 \fB\-\-single\-step\fR
366 .RS 4
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\&.
368 .RE
369 .PP
370 \fB\-S\fR
371 .br
372 \fB\-\-single\-line\fR
373 .RS 4
374 Runs in single\-line mode where a newline terminates an SQL command, as a semicolon does\&.
375 .if n \{\
376 .sp
377 .\}
378 .RS 4
379 .it 1 an-trap
380 .nr an-no-space-flag 1
381 .nr an-break-flag 1
382 .br
383 .ps +1
384 \fBNote\fR
385 .ps -1
386 .br
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
388 SQL
389 and meta\-commands on a line the order of execution might not always be clear to the inexperienced user\&.
390 .sp .5v
391 .RE
392 .RE
393 .PP
394 \fB\-t\fR
395 .br
396 \fB\-\-tuples\-only\fR
397 .RS 4
398 Turn off printing of column names and result row count footers, etc\&. This is equivalent to
399 \fB\et\fR
400 or
401 \fB\epset tuples_only\fR\&.
402 .RE
403 .PP
404 \fB\-T \fR\fB\fItable_options\fR\fR
405 .br
406 \fB\-\-table\-attr=\fR\fB\fItable_options\fR\fR
407 .RS 4
408 Specifies options to be placed within the
409 HTML
410 table
411 tag\&. See
412 \fB\epset tableattr\fR
413 for details\&.
414 .RE
415 .PP
416 \fB\-U \fR\fB\fIusername\fR\fR
417 .br
418 \fB\-\-username=\fR\fB\fIusername\fR\fR
419 .RS 4
420 Connect to the database as the user
421 \fIusername\fR
422 instead of the default\&. (You must have permission to do so, of course\&.)
423 .RE
424 .PP
425 \fB\-v \fR\fB\fIassignment\fR\fR
426 .br
427 \fB\-\-set=\fR\fB\fIassignment\fR\fR
428 .br
429 \fB\-\-variable=\fR\fB\fIassignment\fR\fR
430 .RS 4
431 Perform a variable assignment, like the
432 \fB\eset\fR
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\&.
434 .RE
435 .PP
436 \fB\-V\fR
437 .br
438 \fB\-\-version\fR
439 .RS 4
440 Print the
441 psql
442 version and exit\&.
443 .RE
444 .PP
445 \fB\-w\fR
446 .br
447 \fB\-\-no\-password\fR
448 .RS 4
449 Never issue a password prompt\&. If the server requires password authentication and a password is not available from other sources such as a
450 \&.pgpass
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\&.
452 .sp
453 Note that this option will remain set for the entire session, and so it affects uses of the meta\-command
454 \fB\econnect\fR
455 as well as the initial connection attempt\&.
456 .RE
457 .PP
458 \fB\-W\fR
459 .br
460 \fB\-\-password\fR
461 .RS 4
462 Force
463 psql
464 to prompt for a password before connecting to a database, even if the password will not be used\&.
465 .sp
466 If the server requires password authentication and a password is not available from other sources such as a
467 \&.pgpass
468 file,
469 psql
470 will prompt for a password in any case\&. However,
471 psql
472 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
473 \fB\-W\fR
474 to avoid the extra connection attempt\&.
475 .sp
476 Note that this option will remain set for the entire session, and so it affects uses of the meta\-command
477 \fB\econnect\fR
478 as well as the initial connection attempt\&.
479 .RE
480 .PP
481 \fB\-x\fR
482 .br
483 \fB\-\-expanded\fR
484 .RS 4
485 Turn on the expanded table formatting mode\&. This is equivalent to
486 \fB\ex\fR
487 or
488 \fB\epset expanded\fR\&.
489 .RE
490 .PP
491 \fB\-X\fR
492 .br
493 \fB\-\-no\-psqlrc\fR
494 .RS 4
495 Do not read the start\-up file (neither the system\-wide
496 psqlrc
497 file nor the user\*(Aqs
498 ~/\&.psqlrc
499 file)\&.
500 .RE
501 .PP
502 \fB\-z\fR
503 .br
504 \fB\-\-field\-separator\-zero\fR
505 .RS 4
506 Set the field separator for unaligned output to a zero byte\&. This is equivalent to
507 \fB\epset fieldsep_zero\fR\&.
508 .RE
509 .PP
510 \fB\-0\fR
511 .br
512 \fB\-\-record\-separator\-zero\fR
513 .RS 4
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\&.
517 .RE
518 .PP
519 \fB\-1\fR
520 .br
521 \fB\-\-single\-transaction\fR
522 .RS 4
523 This option can only be used in combination with one or more
524 \fB\-c\fR
525 and/or
526 \fB\-f\fR
527 options\&. It causes
528 psql
529 to issue a
530 \fBBEGIN\fR
531 command before the first such option and a
532 \fBCOMMIT\fR
533 command after the last one, thereby wrapping all the commands into a single transaction\&. If any of the commands fails and the variable
534 \fION_ERROR_STOP\fR
535 was set, a
536 \fBROLLBACK\fR
537 command is sent instead\&. This ensures that either all the commands complete successfully, or no changes are applied\&.
538 .sp
539 If the commands themselves contain
540 \fBBEGIN\fR,
541 \fBCOMMIT\fR, or
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\&.
543 .RE
544 .PP
545 \fB\-?\fR
546 .br
547 \fB\-\-help[=\fR\fB\fItopic\fR\fR\fB]\fR
548 .RS 4
549 Show help about
550 psql
551 and exit\&. The optional
552 \fItopic\fR
553 parameter (defaulting to
554 options) selects which part of
555 psql
556 is explained:
557 commands
558 describes
559 psql\*(Aqs backslash commands;
560 options
561 describes the command\-line options that can be passed to
562 psql; and
563 variables
564 shows help about
565 psql
566 configuration variables\&.
567 .RE
568 .SH "EXIT STATUS"
569 .PP
570 psql
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
572 \fION_ERROR_STOP\fR
573 was set\&.
574 .SH "USAGE"
575 .SS "Connecting to a Database"
576 .PP
577 psql
578 is a regular
579 PostgreSQL
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\&.
581 psql
582 can be told about those parameters via command line options, namely
583 \fB\-d\fR,
584 \fB\-h\fR,
585 \fB\-p\fR, and
586 \fB\-U\fR
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,
588 psql
589 will connect via a Unix\-domain socket to a server on the local host, or via TCP/IP to
590 localhost
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\&.
592 .PP
593 When the defaults aren\*(Aqt quite right, you can save yourself some typing by setting the environment variables
594 \fBPGDATABASE\fR,
595 \fBPGHOST\fR,
596 \fBPGPORT\fR
597 and/or
598 \fBPGUSER\fR
599 to appropriate values\&. (For additional environment variables, see
600 Section\ \&32.15\&.) It is also convenient to have a
601 ~/\&.pgpass
602 file to avoid regularly having to type in passwords\&. See
603 Section\ \&32.16
604 for more information\&.
605 .PP
606 An alternative way to specify connection parameters is in a
607 \fIconninfo\fR
608 string or a
609 URI, which is used instead of a database name\&. This mechanism give you very wide control over the connection\&. For example:
610 .sp
611 .if n \{\
612 .RS 4
613 .\}
614 .nf
615 $ \fBpsql "service=myservice sslmode=require"\fR
616 $ \fBpsql postgresql://dbmaster:5433/mydb?sslmode=require\fR
617 .fi
618 .if n \{\
619 .RE
620 .\}
621 .sp
622 This way you can also use
623 LDAP
624 for connection parameter lookup as described in
625 Section\ \&32.18\&. See
626 Section\ \&32.1.2
627 for more information on all the available connection options\&.
628 .PP
629 If the connection could not be made for any reason (e\&.g\&., insufficient privileges, server is not running on the targeted host, etc\&.),
630 psql
631 will return an error and terminate\&.
632 .PP
633 If both standard input and standard output are a terminal, then
634 psql
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"
640 .PP
641 In normal operation,
642 psql
643 provides a prompt with the name of the database to which
644 psql
645 is currently connected, followed by the string
646 =>\&. For example:
647 .sp
648 .if n \{\
649 .RS 4
650 .\}
651 .nf
652 $ \fBpsql testdb\fR
653 psql (18\&.0)
654 Type "help" for help\&.
655
656 testdb=>
657 .fi
658 .if n \{\
659 .RE
660 .\}
661 .PP
662 At the prompt, the user can type in
663 SQL
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\&.
665 .PP
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\&.
674 .PP
675 Whenever a command is executed,
676 psql
677 also polls for asynchronous notification events generated by
678 \fBLISTEN\fR
679 and
680 \fBNOTIFY\fR\&.
681 .PP
682 While C\-style block comments are passed to the server for processing and removal, SQL\-standard comments are removed by
683 psql\&.
684 .SS "Meta\-Commands"
685 .PP
686 Anything you enter in
687 psql
688 that begins with an unquoted backslash is a
689 psql
690 meta\-command that is processed by
691 psql
692 itself\&. These commands make
693 psql
694 more useful for administration or scripting\&. Meta\-commands are often called slash or backslash commands\&.
695 .PP
696 The format of a
697 psql
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\&.
699 .PP
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
701 \en
702 (new line),
703 \et
704 (tab),
705 \eb
706 (backspace),
707 \er
708 (carriage return),
709 \ef
710 (form feed),
711 \e\fIdigits\fR
712 (octal), and
713 \ex\fIdigits\fR
714 (hexadecimal)\&. A backslash preceding any other character within single\-quoted text quotes that single character, whatever it is\&.
715 .PP
716 If an unquoted colon (:) followed by a
717 psql
718 variable name appears within an argument, it is replaced by the variable\*(Aqs value, as described in
719 SQL Interpolation
720 below\&. The forms
721 :\*(Aq\fIvariable_name\fR\*(Aq
722 and
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\&.
727 .PP
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
729 :\fIvariable_name\fR
730 where
731 \fIvariable_name\fR
732 is a
733 psql
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\&.
739 .PP
740 Some commands take an
741 SQL
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,
744 FOO"BAR"BAZ
745 is interpreted as
746 fooBARbaz, and
747 "A weird"" name"
748 becomes
749 A weird" name\&.
750 .PP
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
752 \e\e
753 (two backslashes) marks the end of arguments and continues parsing
754 SQL
755 commands, if any\&. That way
756 SQL
757 and
758 psql
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\&.
760 .PP
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\&.
763 .PP
764 Many of the meta\-commands also allow
765 x
766 to be appended as an option\&. This will cause the results to be displayed in expanded mode, as if
767 \fB\ex\fR
768 or
769 \fB\epset expanded\fR
770 had been used\&.
771 .PP
772 The following meta\-commands are defined:
773 .PP
774 \ea
775 .RS 4
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
777 \fB\epset\fR
778 for a more general solution\&.
779 .RE
780 .PP
781 \ebind [ \fIparameter\fR ] \&.\&.\&.
782 .RS 4
783 Sets query parameters for the next query execution, with the specified parameters passed for any parameter placeholders ($1
784 etc\&.)\&.
785 .sp
786 Example:
787 .sp
788 .if n \{\
789 .RS 4
790 .\}
791 .nf
792 INSERT INTO tbl1 VALUES ($1, $2) \ebind \*(Aqfirst value\*(Aq \*(Aqsecond value\*(Aq \eg
793 .fi
794 .if n \{\
795 .RE
796 .\}
797 .sp
798 This also works for query\-execution commands besides
799 \eg, such as
800 \egx
801 and
802 \egset\&.
803 .sp
804 This command causes the extended query protocol (see
805 Section\ \&54.1.2) to be used, unlike normal
806 psql
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\&.
809 .RE
810 .PP
811 \ebind_named \fIstatement_name\fR [ \fIparameter\fR ] \&.\&.\&.
812 .RS 4
813 \ebind_named
814 is equivalent to
815 \ebind, except that it takes the name of an existing prepared statement as first parameter\&. An empty string denotes the unnamed prepared statement\&.
816 .sp
817 Example:
818 .sp
819 .if n \{\
820 .RS 4
821 .\}
822 .nf
823 INSERT INTO tbls1 VALUES ($1, $2) \eparse stmt1
824 \ebind_named stmt1 \*(Aqfirst value\*(Aq \*(Aqsecond value\*(Aq \eg
825 .fi
826 .if n \{\
827 .RE
828 .\}
829 .sp
830 This command causes the extended query protocol (see
831 Section\ \&54.1.2) to be used, unlike normal
832 psql
833 operation, which uses the simple query protocol\&. So this command can be useful to test the extended query protocol from
834 psql\&.
835 .RE
836 .PP
837 \ec or \econnect [ \-reuse\-previous=\fIon|off\fR ] [ \fIdbname\fR [ \fIusername\fR ] [ \fIhost\fR ] [ \fIport\fR ] | \fIconninfo\fR ]
838 .RS 4
839 Establishes a new connection to a
840 PostgreSQL
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
842 \fIconninfo\fR
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\&.
845 .sp
846 Specifying any of
847 \fIdbname\fR,
848 \fIusername\fR,
849 \fIhost\fR
850 or
851 \fIport\fR
852 as
853 \-
854 is equivalent to omitting that parameter\&.
855 .sp
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
858 \fIconninfo\fR
859 string is given\&. Passing a first argument of
860 \-reuse\-previous=on
861 or
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
864 \fIconninfo\fR
865 string is taken from the existing connection\*(Aqs parameters\&. An exception is that if the
866 \fIhost\fR
867 setting is changed from its previous value using the positional syntax, any
868 \fIhostaddr\fR
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
870 libpq
871 default is used\&.
872 .sp
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
874 psql
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
876 \econnect
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
878 \econnect
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
880 \econnect
881 failure, no parameters are allowed to be re\-used later, since the script would likely be expecting the values from the failed
882 \econnect
883 to be re\-used\&.
884 .sp
885 Examples:
886 .sp
887 .if n \{\
888 .RS 4
889 .\}
890 .nf
891 => \ec mydb myuser host\&.dom 6432
892 => \ec service=foo
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
896 .fi
897 .if n \{\
898 .RE
899 .\}
900 .RE
901 .PP
902 \eC [ \fItitle\fR ]
903 .RS 4
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
907 HTML
908 table\&.)
909 .RE
910 .PP
911 \ecd [ \fIdirectory\fR ]
912 .RS 4
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
915 Section\ \&32.16\&.
916 .if n \{\
917 .sp
918 .\}
919 .RS 4
920 .it 1 an-trap
921 .nr an-no-space-flag 1
922 .nr an-break-flag 1
923 .br
924 .ps +1
925 \fBTip\fR
926 .ps -1
927 .br
928 To print your current working directory, use
929 \e! pwd\&.
930 .sp .5v
931 .RE
932 .RE
933 .PP
934 \eclose_prepared \fIprepared_statement_name\fR
935 .RS 4
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\&.
937 .sp
938 Example:
939 .sp
940 .if n \{\
941 .RS 4
942 .\}
943 .nf
944 SELECT $1 \eparse stmt1
945 \eclose_prepared stmt1
946 .fi
947 .if n \{\
948 .RE
949 .\}
950 .sp
951 This command causes the extended query protocol to be used, unlike normal
952 psql
953 operation, which uses the simple query protocol\&. So this command can be useful to test the extended query protocol from
954 psql\&.
955 .RE
956 .PP
957 \econninfo
958 .RS 4
959 Outputs information about the current database connection, including SSL\-related information if SSL is in use\&.
960 .sp
961 Note that the
962 Client User
963 field shows the user at the time of connection, while the
964 Superuser
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
966 \fBSET ROLE\fR
967 command\&.
968 .RE
969 .PP
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 ]
971 .br
972 \ecopy { \fItable\fR [ ( \fIcolumn_list\fR ) ] | ( \fIquery\fR ) } to { \fI\*(Aqfilename\*(Aq\fR | program \fI\*(Aqcommand\*(Aq\fR | stdout | pstdout } [ [ with ] ( \fIoption\fR [, \&.\&.\&.] ) ]
973 .RS 4
974 Performs a frontend (client) copy\&. This is an operation that runs an
975 SQL
976 \fBCOPY\fR
977 command, but instead of the server reading or writing the specified file,
978 psql
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\&.
980 .sp
981 When
982 program
983 is specified,
984 \fIcommand\fR
985 is executed by
986 psql
987 and the data passed from or to
988 \fIcommand\fR
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\&.
990 .sp
991 For
992 \ecopy \&.\&.\&. from stdin, data rows are read from the same source that issued the command, continuing until a line containing only
993 \e\&.
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
997 psql
998 command output, and the
999 COPY \fIcount\fR
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
1002 \eo
1003 option, write
1004 from pstdin
1005 or
1006 to pstdout\&.
1007 .sp
1008 The syntax of this command is similar to that of the
1009 SQL
1010 \fBCOPY\fR
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
1013 \fB\ecopy\fR
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\&.
1016 .if n \{\
1017 .sp
1018 .\}
1019 .RS 4
1020 .it 1 an-trap
1021 .nr an-no-space-flag 1
1022 .nr an-break-flag 1
1023 .br
1024 .ps +1
1025 \fBTip\fR
1026 .ps -1
1027 .br
1028 Another way to obtain the same result as
1029 \ecopy \&.\&.\&. to
1030 is to use the
1031 SQL
1032 COPY \&.\&.\&. TO STDOUT
1033 command and terminate it with
1034 \eg \fIfilename\fR
1035 or
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\&.
1038 .sp .5v
1039 .RE
1040 .if n \{\
1041 .sp
1042 .\}
1043 .RS 4
1044 .it 1 an-trap
1045 .nr an-no-space-flag 1
1046 .nr an-break-flag 1
1047 .br
1048 .ps +1
1049 \fBTip\fR
1050 .ps -1
1051 .br
1052 These operations are not as efficient as the
1053 SQL
1054 \fBCOPY\fR
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
1056 SQL
1057 command might be preferable\&.
1058 .sp .5v
1059 .RE
1060 .RE
1061 .PP
1062 \ecopyright
1063 .RS 4
1064 Shows the copyright and distribution terms of
1065 PostgreSQL\&.
1066 .RE
1067 .PP
1068 \ecrosstabview [ \fIcolV\fR [ \fIcolH\fR [ \fIcolD\fR [ \fIsortcolH\fR ] ] ] ]
1069 .RS 4
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
1072 \fIcolV\fR
1073 becomes a vertical header and the output column identified by
1074 \fIcolH\fR
1075 becomes a horizontal header\&.
1076 \fIcolD\fR
1077 identifies the output column to display within the grid\&.
1078 \fIsortcolH\fR
1079 identifies an optional sort column for the horizontal header\&.
1080 .sp
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,
1082 \fIcolV\fR
1083 is taken as column 1 and
1084 \fIcolH\fR
1085 as column 2\&.
1086 \fIcolH\fR
1087 must differ from
1088 \fIcolV\fR\&. If
1089 \fIcolD\fR
1090 is not specified, then there must be exactly three columns in the query result, and the column that is neither
1091 \fIcolV\fR
1092 nor
1093 \fIcolH\fR
1094 is taken to be
1095 \fIcolD\fR\&.
1096 .sp
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\&.
1099 .sp
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
1102 \fIsortcolH\fR
1103 argument is given, it identifies a column whose values must be integer numbers, and the values from
1104 \fIcolH\fR
1105 will appear in the horizontal header sorted according to the corresponding
1106 \fIsortcolH\fR
1107 values\&.
1108 .sp
1109 Inside the crosstab grid, for each distinct value
1110 x
1111 of
1112 \fIcolH\fR
1113 and each distinct value
1114 y
1115 of
1116 \fIcolV\fR, the cell located at the intersection
1117 (x,y)
1118 contains the value of the
1119 colD
1120 column in the query result row for which the value of
1121 \fIcolH\fR
1122 is
1123 x
1124 and the value of
1125 \fIcolV\fR
1126 is
1127 y\&. If there is no such row, the cell is empty\&. If there are multiple such rows, an error is reported\&.
1128 .RE
1129 .PP
1130 \ed[Sx+] [ \fIpattern\fR ]
1131 .RS 4
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
1134 NOT NULL
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
1136 is defined in
1137 Patterns
1138 below\&.)
1139 .sp
1140 For some types of relation,
1141 \ed
1142 shows additional information for each column: column values for sequences, indexed expressions for indexes, and foreign data wrapper options for foreign tables\&.
1143 .sp
1144 The command form
1145 \ed+
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
1147 replica identity
1148 setting and the
1149 access method
1150 name if the relation has an access method\&.
1151 .sp
1152 By default, only user\-created objects are shown; supply a pattern or the
1153 S
1154 modifier to include system objects\&.
1155 .if n \{\
1156 .sp
1157 .\}
1158 .RS 4
1159 .it 1 an-trap
1160 .nr an-no-space-flag 1
1161 .nr an-break-flag 1
1162 .br
1163 .ps +1
1164 \fBNote\fR
1165 .ps -1
1166 .br
1167 If
1168 \fB\ed\fR
1169 is used without a
1170 \fIpattern\fR
1171 argument, it is equivalent to
1172 \fB\edtvmsE\fR
1173 which will show a list of all visible tables, views, materialized views, sequences and foreign tables\&. This is purely a convenience measure\&.
1174 .sp
1175 As with many other commands, if
1176 x
1177 is appended to the command name, the results are displayed in expanded mode, but note that this only applies when
1178 \fB\ed\fR
1179 is used without a
1180 \fIpattern\fR
1181 argument, and the
1182 x
1183 modifier cannot appear immediately after the
1184 \fB\ed\fR
1185 (because
1186 \fB\edx\fR
1187 is a different command); the
1188 x
1189 modifier may only appear after an
1190 S
1191 or
1192 +
1193 modifier\&. For example,
1194 \fB\ed+x\fR
1195 is equivalent to
1196 \fB\edtvmsE+x\fR
1197 and will show a list of all relations in expanded mode\&.
1198 .sp .5v
1199 .RE
1200 .RE
1201 .PP
1202 \eda[Sx] [ \fIpattern\fR ]
1203 .RS 4
1204 Lists aggregate functions, together with their return type and the data types they operate on\&. If
1205 \fIpattern\fR
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
1207 S
1208 modifier to include system objects\&. If
1209 x
1210 is appended to the command name, the results are displayed in expanded mode\&.
1211 .RE
1212 .PP
1213 \edA[x+] [ \fIpattern\fR ]
1214 .RS 4
1215 Lists access methods\&. If
1216 \fIpattern\fR
1217 is specified, only access methods whose names match the pattern are shown\&. If
1218 x
1219 is appended to the command name, the results are displayed in expanded mode\&. If
1220 +
1221 is appended to the command name, each access method is listed with its associated handler function and description\&.
1222 .RE
1223 .PP
1224 \edAc[x+] [\fIaccess\-method\-pattern\fR [\fIinput\-type\-pattern\fR]]
1225 .RS 4
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
1232 x
1233 is appended to the command name, the results are displayed in expanded mode\&. If
1234 +
1235 is appended to the command name, each operator class is listed with its associated operator family and owner\&.
1236 .RE
1237 .PP
1238 \edAf[x+] [\fIaccess\-method\-pattern\fR [\fIinput\-type\-pattern\fR]]
1239 .RS 4
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
1246 x
1247 is appended to the command name, the results are displayed in expanded mode\&. If
1248 +
1249 is appended to the command name, each operator family is listed with its owner\&.
1250 .RE
1251 .PP
1252 \edAo[x+] [\fIaccess\-method\-pattern\fR [\fIoperator\-family\-pattern\fR]]
1253 .RS 4
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
1260 x
1261 is appended to the command name, the results are displayed in expanded mode\&. If
1262 +
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\&.
1264 .RE
1265 .PP
1266 \edAp[x+] [\fIaccess\-method\-pattern\fR [\fIoperator\-family\-pattern\fR]]
1267 .RS 4
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
1274 x
1275 is appended to the command name, the results are displayed in expanded mode\&. If
1276 +
1277 is appended to the command name, functions are displayed verbosely, with their actual parameter lists\&.
1278 .RE
1279 .PP
1280 \edb[x+] [ \fIpattern\fR ]
1281 .RS 4
1282 Lists tablespaces\&. If
1283 \fIpattern\fR
1284 is specified, only tablespaces whose names match the pattern are shown\&. If
1285 x
1286 is appended to the command name, the results are displayed in expanded mode\&. If
1287 +
1288 is appended to the command name, each tablespace is listed with its associated options, on\-disk size, permissions and description\&.
1289 .RE
1290 .PP
1291 \edc[Sx+] [ \fIpattern\fR ]
1292 .RS 4
1293 Lists conversions between character\-set encodings\&. If
1294 \fIpattern\fR
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
1296 S
1297 modifier to include system objects\&. If
1298 x
1299 is appended to the command name, the results are displayed in expanded mode\&. If
1300 +
1301 is appended to the command name, each object is listed with its associated description\&.
1302 .RE
1303 .PP
1304 \edconfig[x+] [ \fIpattern\fR ]
1305 .RS 4
1306 Lists server configuration parameters and their values\&. If
1307 \fIpattern\fR
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
1310 \edconfig *
1311 to see all parameters\&.) If
1312 x
1313 is appended to the command name, the results are displayed in expanded mode\&. If
1314 +
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)\&.
1316 .RE
1317 .PP
1318 \edC[x+] [ \fIpattern\fR ]
1319 .RS 4
1320 Lists type casts\&. If
1321 \fIpattern\fR
1322 is specified, only casts whose source or target types match the pattern are listed\&. If
1323 x
1324 is appended to the command name, the results are displayed in expanded mode\&. If
1325 +
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\&.
1327 .RE
1328 .PP
1329 \edd[Sx] [ \fIpattern\fR ]
1330 .RS 4
1331 Shows the descriptions of objects of type
1332 constraint,
1333 operator class,
1334 operator family,
1335 rule, and
1336 trigger\&. All other comments may be viewed by the respective backslash commands for those object types\&.
1337 .sp
1338 \edd
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
1341 S
1342 modifier to include system objects\&. If
1343 x
1344 is appended to the command name, the results are displayed in expanded mode\&.
1345 .sp
1346 Descriptions for objects can be created with the
1347 \fBCOMMENT\fR
1348 SQL
1349 command\&.
1350 .RE
1351 .PP
1352 \edD[Sx+] [ \fIpattern\fR ]
1353 .RS 4
1354 Lists domains\&. If
1355 \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
1357 S
1358 modifier to include system objects\&. If
1359 x
1360 is appended to the command name, the results are displayed in expanded mode\&. If
1361 +
1362 is appended to the command name, each object is listed with its associated permissions and description\&.
1363 .RE
1364 .PP
1365 \eddp[x] [ \fIpattern\fR ]
1366 .RS 4
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
1368 \fIpattern\fR
1369 is specified, only entries whose role name or schema name matches the pattern are listed\&. If
1370 x
1371 is appended to the command name, the results are displayed in expanded mode\&.
1372 .sp
1373 The
1374 \fBALTER DEFAULT PRIVILEGES\fR
1375 command is used to set default access privileges\&. The meaning of the privilege display is explained in
1376 Section\ \&5.8\&.
1377 .RE
1378 .PP
1379 \edE[Sx+] [ \fIpattern\fR ]
1380 .br
1381 \edi[Sx+] [ \fIpattern\fR ]
1382 .br
1383 \edm[Sx+] [ \fIpattern\fR ]
1384 .br
1385 \eds[Sx+] [ \fIpattern\fR ]
1386 .br
1387 \edt[Sx+] [ \fIpattern\fR ]
1388 .br
1389 \edv[Sx+] [ \fIpattern\fR ]
1390 .RS 4
1391 In this group of commands, the letters
1392 E,
1393 i,
1394 m,
1395 s,
1396 t, and
1397 v
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,
1399 \edti
1400 lists tables and indexes\&. If
1401 x
1402 is appended to the command name, the results are displayed in expanded mode\&. If
1403 +
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
1405 \fIpattern\fR
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
1407 S
1408 modifier to include system objects\&.
1409 .RE
1410 .PP
1411 \edes[x+] [ \fIpattern\fR ]
1412 .RS 4
1413 Lists foreign servers (mnemonic:
1414 \(lqexternal servers\(rq)\&. If
1415 \fIpattern\fR
1416 is specified, only those servers whose name matches the pattern are listed\&. If
1417 x
1418 is appended to the command name, the results are displayed in expanded mode\&. If
1419 +
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\&.
1421 .RE
1422 .PP
1423 \edet[x+] [ \fIpattern\fR ]
1424 .RS 4
1425 Lists foreign tables (mnemonic:
1426 \(lqexternal tables\(rq)\&. If
1427 \fIpattern\fR
1428 is specified, only entries whose table name or schema name matches the pattern are listed\&. If
1429 x
1430 is appended to the command name, the results are displayed in expanded mode\&. If
1431 +
1432 is appended to the command name, generic options and the foreign table description are also displayed\&.
1433 .RE
1434 .PP
1435 \edeu[x+] [ \fIpattern\fR ]
1436 .RS 4
1437 Lists user mappings (mnemonic:
1438 \(lqexternal users\(rq)\&. If
1439 \fIpattern\fR
1440 is specified, only those mappings whose user names match the pattern are listed\&. If
1441 x
1442 is appended to the command name, the results are displayed in expanded mode\&. If
1443 +
1444 is appended to the command name, additional information about each mapping is shown\&.
1445 .if n \{\
1446 .sp
1447 .\}
1448 .RS 4
1449 .it 1 an-trap
1450 .nr an-no-space-flag 1
1451 .nr an-break-flag 1
1452 .br
1453 .ps +1
1454 \fBCaution\fR
1455 .ps -1
1456 .br
1457 \edeu+
1458 might also display the user name and password of the remote user, so care should be taken not to disclose them\&.
1459 .sp .5v
1460 .RE
1461 .RE
1462 .PP
1463 \edew[x+] [ \fIpattern\fR ]
1464 .RS 4
1465 Lists foreign\-data wrappers (mnemonic:
1466 \(lqexternal wrappers\(rq)\&. If
1467 \fIpattern\fR
1468 is specified, only those foreign\-data wrappers whose name matches the pattern are listed\&. If
1469 x
1470 is appended to the command name, the results are displayed in expanded mode\&. If
1471 +
1472 is appended to the command name, the access privileges, options, and description of the foreign\-data wrapper are also shown\&.
1473 .RE
1474 .PP
1475 \edf[anptwSx+] [ \fIpattern\fR [ \fIarg_pattern\fR \&.\&.\&. ] ]
1476 .RS 4
1477 Lists functions, together with their result data types, argument data types, and function types, which are classified as
1478 \(lqagg\(rq
1479 (aggregate),
1480 \(lqnormal\(rq,
1481 \(lqprocedure\(rq,
1482 \(lqtrigger\(rq, or
1483 \(lqwindow\(rq\&. To display only functions of specific type(s), add the corresponding letters
1484 a,
1485 n,
1486 p,
1487 t, or
1488 w
1489 to the command\&. If
1490 \fIpattern\fR
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
1492 \-
1493 as the last
1494 \fIarg_pattern\fR\&.) By default, only user\-created objects are shown; supply a pattern or the
1495 S
1496 modifier to include system objects\&. If
1497 x
1498 is appended to the command name, the results are displayed in expanded mode\&. If
1499 +
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
1501 \esf\&.
1502 .RE
1503 .PP
1504 \edF[x+] [ \fIpattern\fR ]
1505 .RS 4
1506 Lists text search configurations\&. If
1507 \fIpattern\fR
1508 is specified, only configurations whose names match the pattern are shown\&. If
1509 x
1510 is appended to the command name, the results are displayed in expanded mode\&. If
1511 +
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\&.
1513 .RE
1514 .PP
1515 \edFd[x+] [ \fIpattern\fR ]
1516 .RS 4
1517 Lists text search dictionaries\&. If
1518 \fIpattern\fR
1519 is specified, only dictionaries whose names match the pattern are shown\&. If
1520 x
1521 is appended to the command name, the results are displayed in expanded mode\&. If
1522 +
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\&.
1524 .RE
1525 .PP
1526 \edFp[x+] [ \fIpattern\fR ]
1527 .RS 4
1528 Lists text search parsers\&. If
1529 \fIpattern\fR
1530 is specified, only parsers whose names match the pattern are shown\&. If
1531 x
1532 is appended to the command name, the results are displayed in expanded mode\&. If
1533 +
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\&.
1535 .RE
1536 .PP
1537 \edFt[x+] [ \fIpattern\fR ]
1538 .RS 4
1539 Lists text search templates\&. If
1540 \fIpattern\fR
1541 is specified, only templates whose names match the pattern are shown\&. If
1542 x
1543 is appended to the command name, the results are displayed in expanded mode\&. If
1544 +
1545 is appended to the command name, additional information is shown about each template, including the underlying function names\&.
1546 .RE
1547 .PP
1548 \edg[Sx+] [ \fIpattern\fR ]
1549 .RS 4
1550 Lists database roles\&. (Since the concepts of
1551 \(lqusers\(rq
1552 and
1553 \(lqgroups\(rq
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
1557 S
1558 modifier to include system roles\&. If
1559 \fIpattern\fR
1560 is specified, only those roles whose names match the pattern are listed\&. If
1561 x
1562 is appended to the command name, the results are displayed in expanded mode\&. If
1563 +
1564 is appended to the command name, additional information is shown about each role; currently this adds the comment for each role\&.
1565 .RE
1566 .PP
1567 \edl[x+]
1568 .RS 4
1569 This is an alias for
1570 \fB\elo_list\fR, which shows a list of large objects\&. If
1571 x
1572 is appended to the command name, the results are displayed in expanded mode\&. If
1573 +
1574 is appended to the command name, each large object is listed with its associated permissions, if any\&.
1575 .RE
1576 .PP
1577 \edL[Sx+] [ \fIpattern\fR ]
1578 .RS 4
1579 Lists procedural languages\&. If
1580 \fIpattern\fR
1581 is specified, only languages whose names match the pattern are listed\&. By default, only user\-created languages are shown; supply the
1582 S
1583 modifier to include system objects\&. If
1584 x
1585 is appended to the command name, the results are displayed in expanded mode\&. If
1586 +
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\&.
1588 .RE
1589 .PP
1590 \edn[Sx+] [ \fIpattern\fR ]
1591 .RS 4
1592 Lists schemas (namespaces)\&. If
1593 \fIpattern\fR
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
1595 S
1596 modifier to include system objects\&. If
1597 x
1598 is appended to the command name, the results are displayed in expanded mode\&. If
1599 +
1600 is appended to the command name, each object is listed with its associated permissions and description, if any\&.
1601 .RE
1602 .PP
1603 \edo[Sx+] [ \fIpattern\fR [ \fIarg_pattern\fR [ \fIarg_pattern\fR ] ] ]
1604 .RS 4
1605 Lists operators with their operand and result types\&. If
1606 \fIpattern\fR
1607 is specified, only operators whose names match the pattern are listed\&. If one
1608 \fIarg_pattern\fR
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
1611 \-
1612 for the unused argument of a unary operator\&.) By default, only user\-created objects are shown; supply a pattern or the
1613 S
1614 modifier to include system objects\&. If
1615 x
1616 is appended to the command name, the results are displayed in expanded mode\&. If
1617 +
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\&.
1619 .RE
1620 .PP
1621 \edO[Sx+] [ \fIpattern\fR ]
1622 .RS 4
1623 Lists collations\&. If
1624 \fIpattern\fR
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
1626 S
1627 modifier to include system objects\&. If
1628 x
1629 is appended to the command name, the results are displayed in expanded mode\&. If
1630 +
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\&.
1632 .RE
1633 .PP
1634 \edp[Sx] [ \fIpattern\fR ]
1635 .RS 4
1636 Lists tables, views and sequences with their associated access privileges\&. If
1637 \fIpattern\fR
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
1639 S
1640 modifier to include system objects\&. If
1641 x
1642 is appended to the command name, the results are displayed in expanded mode\&.
1643 .sp
1644 The
1645 \fBGRANT\fR
1646 and
1647 \fBREVOKE\fR
1648 commands are used to set access privileges\&. The meaning of the privilege display is explained in
1649 Section\ \&5.8\&.
1650 .RE
1651 .PP
1652 \edP[itnx+] [ \fIpattern\fR ]
1653 .RS 4
1654 Lists partitioned relations\&. If
1655 \fIpattern\fR
1656 is specified, only entries whose name matches the pattern are listed\&. The modifiers
1657 t
1658 (tables) and
1659 i
1660 (indexes) can be appended to the command, filtering the kind of relations to list\&. By default, partitioned tables and indexes are listed\&.
1661 .sp
1662 If the modifier
1663 n
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\&.
1665 .sp
1666 If
1667 x
1668 is appended to the command name, the results are displayed in expanded mode\&. If
1669 +
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
1671 n
1672 is combined with
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\&.
1674 .RE
1675 .PP
1676 \edrds[x] [ \fIrole\-pattern\fR [ \fIdatabase\-pattern\fR ] ]
1677 .RS 4
1678 Lists defined configuration settings\&. These settings can be role\-specific, database\-specific, or both\&.
1679 \fIrole\-pattern\fR
1680 and
1681 \fIdatabase\-pattern\fR
1682 are used to select specific roles and databases to list, respectively\&. If omitted, or if
1683 *
1684 is specified, all settings are listed, including those not role\-specific or database\-specific, respectively\&. If
1685 x
1686 is appended to the command name, the results are displayed in expanded mode\&.
1687 .sp
1688 The
1689 \fBALTER ROLE\fR
1690 and
1691 \fBALTER DATABASE\fR
1692 commands are used to define per\-role and per\-database configuration settings\&.
1693 .RE
1694 .PP
1695 \edrg[Sx] [ \fIpattern\fR ]
1696 .RS 4
1697 Lists information about each granted role membership, including assigned options (ADMIN,
1698 INHERIT
1699 and/or
1700 SET) and grantor\&. See the
1701 \fBGRANT\fR
1702 command for information about role memberships\&.
1703 .sp
1704 By default, only grants to user\-created roles are shown; supply the
1705 S
1706 modifier to include system roles\&. If
1707 \fIpattern\fR
1708 is specified, only grants to those roles whose names match the pattern are listed\&. If
1709 x
1710 is appended to the command name, the results are displayed in expanded mode\&.
1711 .RE
1712 .PP
1713 \edRp[x+] [ \fIpattern\fR ]
1714 .RS 4
1715 Lists replication publications\&. If
1716 \fIpattern\fR
1717 is specified, only those publications whose names match the pattern are listed\&. If
1718 x
1719 is appended to the command name, the results are displayed in expanded mode\&. If
1720 +
1721 is appended to the command name, the tables and schemas associated with each publication are shown as well\&.
1722 .RE
1723 .PP
1724 \edRs[x+] [ \fIpattern\fR ]
1725 .RS 4
1726 Lists replication subscriptions\&. If
1727 \fIpattern\fR
1728 is specified, only those subscriptions whose names match the pattern are listed\&. If
1729 x
1730 is appended to the command name, the results are displayed in expanded mode\&. If
1731 +
1732 is appended to the command name, additional properties of the subscriptions are shown\&.
1733 .RE
1734 .PP
1735 \edT[Sx+] [ \fIpattern\fR ]
1736 .RS 4
1737 Lists data types\&. If
1738 \fIpattern\fR
1739 is specified, only types whose names match the pattern are listed\&. If
1740 x
1741 is appended to the command name, the results are displayed in expanded mode\&. If
1742 +
1743 is appended to the command name, each type is listed with its internal name and size, its allowed values if it is an
1744 enum
1745 type, and its associated permissions\&. By default, only user\-created objects are shown; supply a pattern or the
1746 S
1747 modifier to include system objects\&.
1748 .RE
1749 .PP
1750 \edu[Sx+] [ \fIpattern\fR ]
1751 .RS 4
1752 Lists database roles\&. (Since the concepts of
1753 \(lqusers\(rq
1754 and
1755 \(lqgroups\(rq
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
1759 S
1760 modifier to include system roles\&. If
1761 \fIpattern\fR
1762 is specified, only those roles whose names match the pattern are listed\&. If
1763 x
1764 is appended to the command name, the results are displayed in expanded mode\&. If
1765 +
1766 is appended to the command name, additional information is shown about each role; currently this adds the comment for each role\&.
1767 .RE
1768 .PP
1769 \edx[x+] [ \fIpattern\fR ]
1770 .RS 4
1771 Lists installed extensions\&. If
1772 \fIpattern\fR
1773 is specified, only those extensions whose names match the pattern are listed\&. If
1774 x
1775 is appended to the command name, the results are displayed in expanded mode\&. If
1776 +
1777 is appended to the command name, all the objects belonging to each matching extension are listed\&.
1778 .RE
1779 .PP
1780 \edX[x] [ \fIpattern\fR ]
1781 .RS 4
1782 Lists extended statistics\&. If
1783 \fIpattern\fR
1784 is specified, only those extended statistics whose names match the pattern are listed\&. If
1785 x
1786 is appended to the command name, the results are displayed in expanded mode\&.
1787 .sp
1788 The status of each kind of extended statistics is shown in a column named after its statistic kind (e\&.g\&. Ndistinct)\&.
1789 defined
1790 means that it was requested when creating the statistics, and NULL means it wasn\*(Aqt requested\&. You can use
1791 pg_stats_ext
1792 if you\*(Aqd like to know whether
1793 \fBANALYZE\fR
1794 was run and statistics are available to the planner\&.
1795 .RE
1796 .PP
1797 \edy[x+] [ \fIpattern\fR ]
1798 .RS 4
1799 Lists event triggers\&. If
1800 \fIpattern\fR
1801 is specified, only those event triggers whose names match the pattern are listed\&. If
1802 x
1803 is appended to the command name, the results are displayed in expanded mode\&. If
1804 +
1805 is appended to the command name, each object is listed with its associated description\&.
1806 .RE
1807 .PP
1808 \ee or \eedit [ \fIfilename\fR ] [ \fIline_number\fR ]
1809 .RS 4
1810 If
1811 \fIfilename\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
1813 \fIfilename\fR
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\&.
1815 .sp
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
1818 \eg
1819 to send it, or
1820 \er
1821 to cancel it by clearing the query buffer\&.
1822 .sp
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
1824 \fB\ei\fR
1825 for that\&.)
1826 .sp
1827 If a line number is specified,
1828 psql
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,
1830 psql
1831 assumes it is a line number, not a file name\&.
1832 .if n \{\
1833 .sp
1834 .\}
1835 .RS 4
1836 .it 1 an-trap
1837 .nr an-no-space-flag 1
1838 .nr an-break-flag 1
1839 .br
1840 .ps +1
1841 \fBTip\fR
1842 .ps -1
1843 .br
1844 See
1845 Environment, below, for how to configure and customize your editor\&.
1846 .sp .5v
1847 .RE
1848 .RE
1849 .PP
1850 \eecho \fItext\fR [ \&.\&.\&. ]
1851 .RS 4
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:
1853 .sp
1854 .if n \{\
1855 .RS 4
1856 .\}
1857 .nf
1858 => \fB\eecho `date`\fR
1859 Tue Oct 26 21:40:57 CEST 1999
1860 .fi
1861 .if n \{\
1862 .RE
1863 .\}
1864 .sp
1865 If the first argument is an unquoted
1866 \-n
1867 the trailing newline is not written (nor is the first argument)\&.
1868 .if n \{\
1869 .sp
1870 .\}
1871 .RS 4
1872 .it 1 an-trap
1873 .nr an-no-space-flag 1
1874 .nr an-break-flag 1
1875 .br
1876 .ps +1
1877 \fBTip\fR
1878 .ps -1
1879 .br
1880 If you use the
1881 \fB\eo\fR
1882 command to redirect your query output you might wish to use
1883 \fB\eqecho\fR
1884 instead of this command\&. See also
1885 \fB\ewarn\fR\&.
1886 .sp .5v
1887 .RE
1888 .RE
1889 .PP
1890 \eef [ \fIfunction_description\fR [ \fIline_number\fR ] ]
1891 .RS 4
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
1894 or
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
1898 \eg
1899 to send it, or
1900 \er
1901 to cancel\&.
1902 .sp
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\&.
1905 .sp
1906 If no function is specified, a blank
1907 \fBCREATE FUNCTION\fR
1908 template is presented for editing\&.
1909 .sp
1910 If a line number is specified,
1911 psql
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\&.)
1913 .sp
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\&.
1916 .if n \{\
1917 .sp
1918 .\}
1919 .RS 4
1920 .it 1 an-trap
1921 .nr an-no-space-flag 1
1922 .nr an-break-flag 1
1923 .br
1924 .ps +1
1925 \fBTip\fR
1926 .ps -1
1927 .br
1928 See
1929 Environment, below, for how to configure and customize your editor\&.
1930 .sp .5v
1931 .RE
1932 .RE
1933 .PP
1934 \eencoding [ \fIencoding\fR ]
1935 .RS 4
1936 Sets the client character set encoding\&. Without an argument, this command shows the current encoding\&.
1937 .RE
1938 .PP
1939 \eerrverbose
1940 .RS 4
1941 Repeats the most recent server error message at maximum verbosity, as though
1942 \fIVERBOSITY\fR
1943 were set to
1944 verbose
1945 and
1946 \fISHOW_CONTEXT\fR
1947 were set to
1948 always\&.
1949 .RE
1950 .PP
1951 \eev [ \fIview_name\fR [ \fIline_number\fR ] ]
1952 .RS 4
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
1957 \eg
1958 to send it, or
1959 \er
1960 to cancel\&.
1961 .sp
1962 If no view is specified, a blank
1963 \fBCREATE VIEW\fR
1964 template is presented for editing\&.
1965 .sp
1966 If a line number is specified,
1967 psql
1968 will position the cursor on the specified line of the view definition\&.
1969 .sp
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\&.
1972 .RE
1973 .PP
1974 \ef [ \fIstring\fR ]
1975 .RS 4
1976 Sets the field separator for unaligned query output\&. The default is the vertical bar (|)\&. It is equivalent to
1977 \fB\epset fieldsep\fR\&.
1978 .RE
1979 .PP
1980 \eg [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ \fIfilename\fR ]
1981 .br
1982 \eg [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ |\fIcommand\fR ]
1983 .RS 4
1984 Sends the current query buffer to the server for execution\&.
1985 .sp
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
1990 \epset
1991 \fIoption\fR
1992 \fIvalue\fR
1993 commands, but take effect only for the duration of this query\&. In this list, spaces are not allowed around
1994 =
1995 signs, but are required between option clauses\&. If
1996 =\fIvalue\fR
1997 is omitted, the named
1998 \fIoption\fR
1999 is changed in the same way as for
2000 \epset
2001 \fIoption\fR
2002 with no explicit
2003 \fIvalue\fR\&.
2004 .sp
2005 If a
2006 \fIfilename\fR
2007 or
2008 |\fIcommand\fR
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\&.
2010 .sp
2011 If the current query buffer is empty, the most recently sent query is re\-executed instead\&. Except for that behavior,
2012 \eg
2013 without any arguments is essentially equivalent to a semicolon\&. With arguments,
2014 \eg
2015 provides a
2016 \(lqone\-shot\(rq
2017 alternative to the
2018 \fB\eo\fR
2019 command, and additionally allows one\-shot adjustments of the output formatting options normally set by
2020 \epset\&.
2021 .sp
2022 When the last argument begins with
2023 |, the entire remainder of the line is taken to be the
2024 \fIcommand\fR
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\&.
2026 .RE
2027 .PP
2028 \egdesc
2029 .RS 4
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\&.
2031 .sp
2032 If the current query buffer is empty, the most recently sent query is described instead\&.
2033 .RE
2034 .PP
2035 \egetenv \fIpsql_var\fR \fIenv_var\fR
2036 .RS 4
2037 Gets the value of the environment variable
2038 \fIenv_var\fR
2039 and assigns it to the
2040 psql
2041 variable
2042 \fIpsql_var\fR\&. If
2043 \fIenv_var\fR
2044 is not defined in the
2045 psql
2046 process\*(Aqs environment,
2047 \fIpsql_var\fR
2048 is not changed\&. Example:
2049 .sp
2050 .if n \{\
2051 .RS 4
2052 .\}
2053 .nf
2054 => \fB\egetenv home HOME\fR
2055 => \fB\eecho :home\fR
2056 /home/postgres
2057 .fi
2058 .if n \{\
2059 .RE
2060 .\}
2061 .RE
2062 .PP
2063 \egexec
2064 .RS 4
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
2066 my_table:
2067 .sp
2068 .if n \{\
2069 .RS 4
2070 .\}
2071 .nf
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
2076 \-> \fB\egexec\fR
2077 CREATE INDEX
2078 CREATE INDEX
2079 CREATE INDEX
2080 CREATE INDEX
2081 .fi
2082 .if n \{\
2083 .RE
2084 .\}
2085 .sp
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
2087 psql
2088 meta\-commands nor contain
2089 psql
2090 variable references\&. If any individual query fails, execution of the remaining queries continues unless
2091 \fION_ERROR_STOP\fR
2092 is set\&. Execution of each query is subject to
2093 \fIECHO\fR
2094 processing\&. (Setting
2095 \fIECHO\fR
2096 to
2097 all
2098 or
2099 queries
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\&.
2102 .sp
2103 If the current query buffer is empty, the most recently sent query is re\-executed instead\&.
2104 .RE
2105 .PP
2106 \egset [ \fIprefix\fR ]
2107 .RS 4
2108 Sends the current query buffer to the server and stores the query\*(Aqs output into
2109 psql
2110 variables (see
2111 Variables
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:
2113 .sp
2114 .if n \{\
2115 .RS 4
2116 .\}
2117 .nf
2118 => \fBSELECT \*(Aqhello\*(Aq AS var1, 10 AS var2\fR
2119 \-> \fB\egset\fR
2120 => \fB\eecho :var1 :var2\fR
2121 hello 10
2122 .fi
2123 .if n \{\
2124 .RE
2125 .\}
2126 .sp
2127 If you specify a
2128 \fIprefix\fR, that string is prepended to the query\*(Aqs column names to create the variable names to use:
2129 .sp
2130 .if n \{\
2131 .RS 4
2132 .\}
2133 .nf
2134 => \fBSELECT \*(Aqhello\*(Aq AS var1, 10 AS var2\fR
2135 \-> \fB\egset result_\fR
2136 => \fB\eecho :result_var1 :result_var2\fR
2137 hello 10
2138 .fi
2139 .if n \{\
2140 .RE
2141 .\}
2142 .sp
2143 If a column result is NULL, the corresponding variable is unset rather than being set\&.
2144 .sp
2145 If the query fails or does not return one row, no variables are changed\&.
2146 .sp
2147 If the current query buffer is empty, the most recently sent query is re\-executed instead\&.
2148 .RE
2149 .PP
2150 \egx [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ \fIfilename\fR ]
2151 .br
2152 \egx [ (\fIoption\fR=\fIvalue\fR [\&.\&.\&.]) ] [ |\fIcommand\fR ]
2153 .RS 4
2154 \egx
2155 is equivalent to
2156 \eg, except that it forces expanded output mode for this query, as if
2157 expanded=on
2158 were included in the list of
2159 \epset
2160 options\&. See also
2161 \ex\&.
2162 .RE
2163 .PP
2164 \eh or \ehelp [ \fIcommand\fR ]
2165 .RS 4
2166 Gives syntax help on the specified
2167 SQL
2168 command\&. If
2169 \fIcommand\fR
2170 is not specified, then
2171 psql
2172 will list all the commands for which syntax help is available\&. If
2173 \fIcommand\fR
2174 is an asterisk (*), then syntax help on all
2175 SQL
2176 commands is shown\&.
2177 .sp
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\&.
2180 .if n \{\
2181 .sp
2182 .\}
2183 .RS 4
2184 .it 1 an-trap
2185 .nr an-no-space-flag 1
2186 .nr an-break-flag 1
2187 .br
2188 .ps +1
2189 \fBNote\fR
2190 .ps -1
2191 .br
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\&.
2194 .sp .5v
2195 .RE
2196 .RE
2197 .PP
2198 \eH or \ehtml
2199 .RS 4
2200 Turns on
2201 HTML
2202 query output format\&. If the
2203 HTML
2204 format is already on, it is switched back to the default aligned text format\&. This command is for compatibility and convenience, but see
2205 \fB\epset\fR
2206 about setting other output options\&.
2207 .RE
2208 .PP
2209 \ei or \einclude \fIfilename\fR
2210 .RS 4
2211 Reads input from the file
2212 \fIfilename\fR
2213 and executes it as though it had been typed on the keyboard\&.
2214 .sp
2215 If
2216 \fIfilename\fR
2217 is
2218 \-
2219 (hyphen), then standard input is read until an EOF indication or
2220 \fB\eq\fR
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\&.
2222 .if n \{\
2223 .sp
2224 .\}
2225 .RS 4
2226 .it 1 an-trap
2227 .nr an-no-space-flag 1
2228 .nr an-break-flag 1
2229 .br
2230 .ps +1
2231 \fBNote\fR
2232 .ps -1
2233 .br
2234 If you want to see the lines on the screen as they are read you must set the variable
2235 \fIECHO\fR
2236 to
2237 all\&.
2238 .sp .5v
2239 .RE
2240 .RE
2241 .PP
2242 \eif \fIexpression\fR
2243 .br
2244 \eelif \fIexpression\fR
2245 .br
2246 \eelse
2247 .br
2248 \eendif
2249 .RS 4
2250 This group of commands implements nestable conditional blocks\&. A conditional block must begin with an
2251 \fB\eif\fR
2252 and end with an
2253 \fB\eendif\fR\&. In between there may be any number of
2254 \fB\eelif\fR
2255 clauses, which may optionally be followed by a single
2256 \fB\eelse\fR
2257 clause\&. Ordinary queries and other types of backslash commands may (and usually do) appear between the commands forming a conditional block\&.
2258 .sp
2259 The
2260 \fB\eif\fR
2261 and
2262 \fB\eelif\fR
2263 commands read their argument(s) and evaluate them as a Boolean expression\&. If the expression yields
2264 true
2265 then processing continues normally; otherwise, lines are skipped until a matching
2266 \fB\eelif\fR,
2267 \fB\eelse\fR, or
2268 \fB\eendif\fR
2269 is reached\&. Once an
2270 \fB\eif\fR
2271 or
2272 \fB\eelif\fR
2273 test has succeeded, the arguments of later
2274 \fB\eelif\fR
2275 commands in the same block are not evaluated but are treated as false\&. Lines following an
2276 \fB\eelse\fR
2277 are processed only if no earlier matching
2278 \fB\eif\fR
2279 or
2280 \fB\eelif\fR
2281 succeeded\&.
2282 .sp
2283 The
2284 \fIexpression\fR
2285 argument of an
2286 \fB\eif\fR
2287 or
2288 \fB\eelif\fR
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:
2290 true,
2291 false,
2292 1,
2293 0,
2294 on,
2295 off,
2296 yes,
2297 no\&. For example,
2298 t,
2299 T, and
2300 tR
2301 will all be considered to be
2302 true\&.
2303 .sp
2304 Expressions that do not properly evaluate to true or false will generate a warning and be treated as false\&.
2305 .sp
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,
2307 \fB\eelif\fR,
2308 \fB\eelse\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\&.
2310 .sp
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
2314 psql
2315 will raise an error\&.
2316 .sp
2317 Here is an example:
2318 .sp
2319 .if n \{\
2320 .RS 4
2321 .\}
2322 .nf
2323 \-\- check for the existence of two separate records in the database and store
2324 \-\- the results in separate psql variables
2325 SELECT
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
2328 \egset
2329 \eif :is_customer
2330     SELECT * FROM customer WHERE customer_id = 123;
2331 \eelif :is_employee
2332     \eecho \*(Aqis not a customer but is an employee\*(Aq
2333     SELECT * FROM employee WHERE employee_id = 456;
2334 \eelse
2335     \eif yes
2336         \eecho \*(Aqnot a customer or employee\*(Aq
2337     \eelse
2338         \eecho \*(Aqthis will never print\*(Aq
2339     \eendif
2340 \eendif
2341 .fi
2342 .if n \{\
2343 .RE
2344 .\}
2345 .RE
2346 .PP
2347 \eir or \einclude_relative \fIfilename\fR
2348 .RS 4
2349 The
2350 \eir
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,
2353 \eir
2354 interprets file names relative to the directory in which the script is located, rather than the current working directory\&.
2355 .RE
2356 .PP
2357 \el[x+] or \elist[x+] [ \fIpattern\fR ]
2358 .RS 4
2359 List the databases in the server and show their names, owners, character set encodings, and access privileges\&. If
2360 \fIpattern\fR
2361 is specified, only databases whose names match the pattern are listed\&. If
2362 x
2363 is appended to the command name, the results are displayed in expanded mode\&. If
2364 +
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\&.)
2366 .RE
2367 .PP
2368 \elo_export \fIloid\fR \fIfilename\fR
2369 .RS 4
2370 Reads the large object with
2371 OID
2372 \fIloid\fR
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\&.
2376 .if n \{\
2377 .sp
2378 .\}
2379 .RS 4
2380 .it 1 an-trap
2381 .nr an-no-space-flag 1
2382 .nr an-break-flag 1
2383 .br
2384 .ps +1
2385 \fBTip\fR
2386 .ps -1
2387 .br
2388 Use
2389 \fB\elo_list\fR
2390 to find out the large object\*(Aqs
2391 OID\&.
2392 .sp .5v
2393 .RE
2394 .RE
2395 .PP
2396 \elo_import \fIfilename\fR [ \fIcomment\fR ]
2397 .RS 4
2398 Stores the file into a
2399 PostgreSQL
2400 large object\&. Optionally, it associates the given comment with the object\&. Example:
2401 .sp
2402 .if n \{\
2403 .RS 4
2404 .\}
2405 .nf
2406 foo=> \fB\elo_import \*(Aq/home/peter/pictures/photo\&.xcf\*(Aq \*(Aqa picture of me\*(Aq\fR
2407 lo_import 152801
2408 .fi
2409 .if n \{\
2410 .RE
2411 .\}
2412 .sp
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
2414 \fB\elo_list\fR
2415 command\&.
2416 .sp
2417 Note that this command is subtly different from the server\-side
2418 \fBlo_import\fR
2419 because it acts as the local user on the local file system, rather than the server\*(Aqs user and file system\&.
2420 .RE
2421 .PP
2422 \elo_list[x+]
2423 .RS 4
2424 Shows a list of all
2425 PostgreSQL
2426 large objects currently stored in the database, along with any comments provided for them\&. If
2427 x
2428 is appended to the command name, the results are displayed in expanded mode\&. If
2429 +
2430 is appended to the command name, each large object is listed with its associated permissions, if any\&.
2431 .RE
2432 .PP
2433 \elo_unlink \fIloid\fR
2434 .RS 4
2435 Deletes the large object with
2436 OID
2437 \fIloid\fR
2438 from the database\&.
2439 .if n \{\
2440 .sp
2441 .\}
2442 .RS 4
2443 .it 1 an-trap
2444 .nr an-no-space-flag 1
2445 .nr an-break-flag 1
2446 .br
2447 .ps +1
2448 \fBTip\fR
2449 .ps -1
2450 .br
2451 Use
2452 \fB\elo_list\fR
2453 to find out the large object\*(Aqs
2454 OID\&.
2455 .sp .5v
2456 .RE
2457 .RE
2458 .PP
2459 \eo or \eout [ \fIfilename\fR ]
2460 .br
2461 \eo or \eout [ |\fIcommand\fR ]
2462 .RS 4
2463 Arranges to save future query results to the file
2464 \fIfilename\fR
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\&.
2467 .sp
2468 If the argument begins with
2469 |, then the entire remainder of the line is taken to be the
2470 \fIcommand\fR
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\&.
2472 .sp
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\&.
2476 .if n \{\
2477 .sp
2478 .\}
2479 .RS 4
2480 .it 1 an-trap
2481 .nr an-no-space-flag 1
2482 .nr an-break-flag 1
2483 .br
2484 .ps +1
2485 \fBTip\fR
2486 .ps -1
2487 .br
2488 To intersperse text output in between query results, use
2489 \fB\eqecho\fR\&.
2490 .sp .5v
2491 .RE
2492 .RE
2493 .PP
2494 \ep or \eprint
2495 .RS 4
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\&.
2497 .RE
2498 .PP
2499 \eparse \fIstatement_name\fR
2500 .RS 4
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\&.
2502 .sp
2503 Example:
2504 .sp
2505 .if n \{\
2506 .RS 4
2507 .\}
2508 .nf
2509 SELECT $1 \eparse stmt1
2510 .fi
2511 .if n \{\
2512 .RE
2513 .\}
2514 .sp
2515 This command causes the extended query protocol to be used, unlike normal
2516 psql
2517 operation, which uses the simple query protocol\&. A
2518 Parse (F)
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\&.
2521 .RE
2522 .PP
2523 \epassword [ \fIusername\fR ]
2524 .RS 4
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
2526 \fBALTER ROLE\fR
2527 command\&. This makes sure that the new password does not appear in cleartext in the command history, the server log, or elsewhere\&.
2528 .RE
2529 .PP
2530 \eprompt [ \fItext\fR ] \fIname\fR
2531 .RS 4
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\&.)
2535 .sp
2536 By default,
2537 \eprompt
2538 uses the terminal for input and output\&. However, if the
2539 \fB\-f\fR
2540 command line switch was used,
2541 \eprompt
2542 uses standard input and standard output\&.
2543 .RE
2544 .PP
2545 \epset [ \fIoption\fR [ \fIvalue\fR ] ]
2546 .RS 4
2547 This command sets options affecting the output of query result tables\&.
2548 \fIoption\fR
2549 indicates which option is to be set\&. The semantics of
2550 \fIvalue\fR
2551 vary depending on the selected option\&. For some options, omitting
2552 \fIvalue\fR
2553 causes the option to be toggled or unset, as described under the particular option\&. If no such behavior is mentioned, then omitting
2554 \fIvalue\fR
2555 just results in the current setting being displayed\&.
2556 .sp
2557 \fB\epset\fR
2558 without any arguments displays the current status of all printing options\&.
2559 .sp
2560 Adjustable printing options are:
2561 .PP
2562 border
2563 .RS 4
2564 The
2565 \fIvalue\fR
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
2567 HTML
2568 format, this will translate directly into the
2569 border=\&.\&.\&.
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
2571 border = 2\&. The
2572 latex
2573 and
2574 latex\-longtable
2575 formats additionally allow a value of 3 to add dividing lines between data rows\&.
2576 .RE
2577 .PP
2578 columns
2579 .RS 4
2580 Sets the target width for the
2581 wrapped
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
2584 \fBCOLUMNS\fR
2585 is not set\&. In addition, if
2586 columns
2587 is zero then the
2588 wrapped
2589 format only affects screen output\&. If
2590 columns
2591 is nonzero then file and pipe output is wrapped to that width as well\&.
2592 .RE
2593 .PP
2594 csv_fieldsep
2595 .RS 4
2596 Specifies the field separator to be used in
2597 CSV
2598 output format\&. If the separator character appears in a field\*(Aqs value, that field is output within double quotes, following standard
2599 CSV
2600 rules\&. The default is a comma\&.
2601 .RE
2602 .PP
2603 expanded (or x)
2604 .RS 4
2605 If
2606 \fIvalue\fR
2607 is specified it must be either
2608 on
2609 or
2610 off, which will enable or disable expanded mode, or
2611 auto\&. If
2612 \fIvalue\fR
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
2614 \(lqhorizontal\(rq
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\&.
2616 .RE
2617 .PP
2618 fieldsep
2619 .RS 4
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
2622 \*(Aq|\*(Aq
2623 (a vertical bar)\&.
2624 .RE
2625 .PP
2626 fieldsep_zero
2627 .RS 4
2628 Sets the field separator to use in unaligned output format to a zero byte\&.
2629 .RE
2630 .PP
2631 footer
2632 .RS 4
2633 If
2634 \fIvalue\fR
2635 is specified it must be either
2636 on
2637 or
2638 off
2639 which will enable or disable display of the table footer (the
2640 (\fIn\fR rows)
2641 count)\&. If
2642 \fIvalue\fR
2643 is omitted the command toggles footer display on or off\&.
2644 .RE
2645 .PP
2646 format
2647 .RS 4
2648 Sets the output format to one of
2649 aligned,
2650 asciidoc,
2651 csv,
2652 html,
2653 latex,
2654 latex\-longtable,
2655 troff\-ms,
2656 unaligned, or
2657 wrapped\&. Unique abbreviations are allowed\&.
2658 .sp
2659 aligned
2660 format is the standard, human\-readable, nicely formatted text output; this is the default\&.
2661 .sp
2662 unaligned
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
2664 CSV
2665 format may be better suited for such purposes\&.
2666 .sp
2667 csv
2668 format
2669
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
2672 \fBCOPY\fR
2673 command\&. A header line with column names is generated unless the
2674 tuples_only
2675 parameter is
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\&.
2678 .sp
2679 wrapped
2680 format is like
2681 aligned
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
2683 columns
2684 option\&. Note that
2685 psql
2686 will not attempt to wrap column header titles; therefore,
2687 wrapped
2688 format behaves the same as
2689 aligned
2690 if the total width needed for column headers exceeds the target\&.
2691 .sp
2692 The
2693 asciidoc,
2694 html,
2695 latex,
2696 latex\-longtable, and
2697 troff\-ms
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
2699 HTML, but in
2700 LaTeX
2701 you must have a complete document wrapper\&. The
2702 latex
2703 format uses
2704 LaTeX\*(Aqs
2705 tabular
2706 environment\&. The
2707 latex\-longtable
2708 format requires the
2709 LaTeX
2710 longtable
2711 and
2712 booktabs
2713 packages\&.
2714 .RE
2715 .PP
2716 linestyle
2717 .RS 4
2718 Sets the border line drawing style to one of
2719 ascii,
2720 old\-ascii, or
2721 unicode\&. Unique abbreviations are allowed\&. (That would mean one letter is enough\&.) The default setting is
2722 ascii\&. This option only affects the
2723 aligned
2724 and
2725 wrapped
2726 output formats\&.
2727 .sp
2728 ascii
2729 style uses plain
2730 ASCII
2731 characters\&. Newlines in data are shown using a
2732 +
2733 symbol in the right\-hand margin\&. When the
2734 wrapped
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\&.
2736 .sp
2737 old\-ascii
2738 style uses plain
2739 ASCII
2740 characters, using the formatting style used in
2741 PostgreSQL
2742 8\&.4 and earlier\&. Newlines in data are shown using a
2743 :
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
2745 ;
2746 symbol is used in place of the left\-hand column separator\&.
2747 .sp
2748 unicode
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\&.
2750 .sp
2751 When the
2752 border
2753 setting is greater than zero, the
2754 linestyle
2755 option also determines the characters with which the border lines are drawn\&. Plain
2756 ASCII
2757 characters work everywhere, but Unicode characters look nicer on displays that recognize them\&.
2758 .RE
2759 .PP
2760 null
2761 .RS 4
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\&.
2764 .RE
2765 .PP
2766 numericlocale
2767 .RS 4
2768 If
2769 \fIvalue\fR
2770 is specified it must be either
2771 on
2772 or
2773 off
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
2775 \fIvalue\fR
2776 is omitted the command toggles between regular and locale\-specific numeric output\&.
2777 .RE
2778 .PP
2779 pager
2780 .RS 4
2781 Controls use of a pager program for query and
2782 psql
2783 help output\&. When the
2784 pager
2785 option is
2786 off, the pager program is not used\&. When the
2787 pager
2788 option is
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
2790 pager
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\&.
2793 \epset pager
2794 without a
2795 \fIvalue\fR
2796 toggles pager use on and off\&.
2797 .sp
2798 If the environment variable
2799 \fBPSQL_PAGER\fR
2800 or
2801 \fBPAGER\fR
2802 is set, output to be paged is piped to the specified program\&. Otherwise a platform\-dependent default program (such as
2803 more) is used\&.
2804 .sp
2805 When using the
2806 \ewatch
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
2811 pspg \-\-stream)\&.
2812 .RE
2813 .PP
2814 pager_min_lines
2815 .RS 4
2816 If
2817 pager_min_lines
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\&.
2819 .RE
2820 .PP
2821 recordsep
2822 .RS 4
2823 Specifies the record (line) separator to use in unaligned output format\&. The default is a newline character\&.
2824 .RE
2825 .PP
2826 recordsep_zero
2827 .RS 4
2828 Sets the record separator to use in unaligned output format to a zero byte\&.
2829 .RE
2830 .PP
2831 tableattr (or T)
2832 .RS 4
2833 In
2834 HTML
2835 format, this specifies attributes to be placed inside the
2836 table
2837 tag\&. This could for example be
2838 cellpadding
2839 or
2840 bgcolor\&. Note that you probably don\*(Aqt want to specify
2841 border
2842 here, as that is already taken care of by
2843 \epset border\&. If no
2844 \fIvalue\fR
2845 is given, the table attributes are unset\&.
2846 .sp
2847 In
2848 latex\-longtable
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\&.
2851 .RE
2852 .PP
2853 title (or C)
2854 .RS 4
2855 Sets the table title for any subsequently printed tables\&. This can be used to give your output descriptive tags\&. If no
2856 \fIvalue\fR
2857 is given, the title is unset\&.
2858 .RE
2859 .PP
2860 tuples_only (or t)
2861 .RS 4
2862 If
2863 \fIvalue\fR
2864 is specified it must be either
2865 on
2866 or
2867 off
2868 which will enable or disable tuples\-only mode\&. If
2869 \fIvalue\fR
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\&.
2871 .RE
2872 .PP
2873 unicode_border_linestyle
2874 .RS 4
2875 Sets the border drawing style for the
2876 unicode
2877 line style to one of
2878 single
2879 or
2880 double\&.
2881 .RE
2882 .PP
2883 unicode_column_linestyle
2884 .RS 4
2885 Sets the column drawing style for the
2886 unicode
2887 line style to one of
2888 single
2889 or
2890 double\&.
2891 .RE
2892 .PP
2893 unicode_header_linestyle
2894 .RS 4
2895 Sets the header drawing style for the
2896 unicode
2897 line style to one of
2898 single
2899 or
2900 double\&.
2901 .RE
2902 .PP
2903 xheader_width
2904 .RS 4
2905 Sets the maximum width of the header for expanded output to one of
2906 full
2907 (the default value),
2908 column,
2909 page, or an
2910 \fIinteger value\fR\&.
2911 .sp
2912 full: the expanded header is not truncated, and will be as wide as the widest output line\&.
2913 .sp
2914 column: truncate the header line to the width of the first column\&.
2915 .sp
2916 page: truncate the header line to the terminal width\&.
2917 .sp
2918 \fIinteger value\fR: specify the exact maximum width of the header line\&.
2919 .RE
2920 .sp
2921 Illustrations of how these different formats look can be seen in
2922 Examples, below\&.
2923 .if n \{\
2924 .sp
2925 .\}
2926 .RS 4
2927 .it 1 an-trap
2928 .nr an-no-space-flag 1
2929 .nr an-break-flag 1
2930 .br
2931 .ps +1
2932 \fBTip\fR
2933 .ps -1
2934 .br
2935 There are various shortcut commands for
2936 \fB\epset\fR\&. See
2937 \fB\ea\fR,
2938 \fB\eC\fR,
2939 \fB\ef\fR,
2940 \fB\eH\fR,
2941 \fB\et\fR,
2942 \fB\eT\fR, and
2943 \fB\ex\fR\&.
2944 .sp .5v
2945 .RE
2946 .RE
2947 .PP
2948 \eq or \equit
2949 .RS 4
2950 Quits the
2951 psql
2952 program\&. In a script file, only execution of that script is terminated\&.
2953 .RE
2954 .PP
2955 \eqecho \fItext\fR [ \&.\&.\&. ]
2956 .RS 4
2957 This command is identical to
2958 \fB\eecho\fR
2959 except that the output will be written to the query output channel, as set by
2960 \fB\eo\fR\&.
2961 .RE
2962 .PP
2963 \er or \ereset
2964 .RS 4
2965 Resets (clears) the query buffer\&.
2966 .RE
2967 .PP
2968 \erestrict \fIrestrict_key\fR
2969 .RS 4
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\&.
2972 .sp
2973 This command is primarily intended for use in plain\-text dumps generated by
2974 pg_dump,
2975 pg_dumpall, and
2976 pg_restore, but it may be useful elsewhere\&.
2977 .RE
2978 .PP
2979 \es [ \fIfilename\fR ]
2980 .RS 4
2981 Print
2982 psql\*(Aqs command line history to
2983 \fIfilename\fR\&. If
2984 \fIfilename\fR
2985 is omitted, the history is written to the standard output (using the pager if appropriate)\&. This command is not available if
2986 psql
2987 was built without
2988 Readline
2989 support\&.
2990 .RE
2991 .PP
2992 \eset [ \fIname\fR [ \fIvalue\fR [ \&.\&.\&. ] ] ]
2993 .RS 4
2994 Sets the
2995 psql
2996 variable
2997 \fIname\fR
2998 to
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
3000 \fB\eunset\fR
3001 command\&.
3002 .sp
3003 \fB\eset\fR
3004 without any arguments displays the names and values of all currently\-set
3005 psql
3006 variables\&.
3007 .sp
3008 Valid variable names can contain letters, digits, and underscores\&. See
3009 Variables
3010 below for details\&. Variable names are case\-sensitive\&.
3011 .sp
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
3014 Variables, below\&.
3015 .if n \{\
3016 .sp
3017 .\}
3018 .RS 4
3019 .it 1 an-trap
3020 .nr an-no-space-flag 1
3021 .nr an-break-flag 1
3022 .br
3023 .ps +1
3024 \fBNote\fR
3025 .ps -1
3026 .br
3027 This command is unrelated to the
3028 SQL
3029 command
3030 \fBSET\fR\&.
3031 .sp .5v
3032 .RE
3033 .RE
3034 .PP
3035 \esetenv \fIname\fR [ \fIvalue\fR ]
3036 .RS 4
3037 Sets the environment variable
3038 \fIname\fR
3039 to
3040 \fIvalue\fR, or if the
3041 \fIvalue\fR
3042 is not supplied, unsets the environment variable\&. Example:
3043 .sp
3044 .if n \{\
3045 .RS 4
3046 .\}
3047 .nf
3048 testdb=> \fB\esetenv PAGER less\fR
3049 testdb=> \fB\esetenv LESS \-imx4F\fR
3050 .fi
3051 .if n \{\
3052 .RE
3053 .\}
3054 .RE
3055 .PP
3056 \esf[+] \fIfunction_description\fR
3057 .RS 4
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
3060 or
3061 \fBCREATE OR REPLACE PROCEDURE\fR
3062 command\&. The definition is printed to the current query output channel, as set by
3063 \fB\eo\fR\&.
3064 .sp
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\&.
3067 .sp
3068 If
3069 +
3070 is appended to the command name, then the output lines are numbered, with the first line of the function body being line 1\&.
3071 .sp
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\&.
3074 .RE
3075 .PP
3076 \esv[+] \fIview_name\fR
3077 .RS 4
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
3081 \fB\eo\fR\&.
3082 .sp
3083 If
3084 +
3085 is appended to the command name, then the output lines are numbered from 1\&.
3086 .sp
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\&.
3089 .RE
3090 .PP
3091 \estartpipeline
3092 .br
3093 \esendpipeline
3094 .br
3095 \esyncpipeline
3096 .br
3097 \eendpipeline
3098 .br
3099 \eflushrequest
3100 .br
3101 \eflush
3102 .br
3103 \egetresults [ \fInumber_results\fR ]
3104 .RS 4
3105 This group of commands implements pipelining of SQL statements\&. A pipeline must begin with a
3106 \fB\estartpipeline\fR
3107 and end with an
3108 \fB\eendpipeline\fR\&. In between there may be any number of
3109 \fB\esyncpipeline\fR
3110 commands, which sends a
3111 sync message
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
3113 Section\ \&32.5
3114 for more details\&.
3115 .sp
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
3117 \ebind,
3118 \ebind_named,
3119 \eclose_prepared
3120 or
3121 \eparse
3122 can be used in an ongoing pipeline\&. While a pipeline is ongoing,
3123 \esendpipeline
3124 will append the current query buffer to the pipeline\&. Other meta\-commands like
3125 \eg,
3126 \egx
3127 or
3128 \egdesc
3129 are not allowed in pipeline mode\&.
3130 .sp
3131 \fB\eflushrequest\fR
3132 appends a flush command to the pipeline, allowing to read results with
3133 \fB\egetresults\fR
3134 without issuing a sync or ending the pipeline\&.
3135 \fB\egetresults\fR
3136 will automatically push unsent data to the server\&.
3137 \fB\eflush\fR
3138 can be used to manually push unsent data\&.
3139 .sp
3140 \fB\egetresults\fR
3141 accepts an optional
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\&.
3147 .sp
3148 When pipeline mode is active, a dedicated prompt variable is available to report the pipeline status\&. See
3149 %P
3150 for more details
3151 .sp
3152 \fBCOPY\fR
3153 is not supported while in pipeline mode\&.
3154 .sp
3155 Example:
3156 .sp
3157 .if n \{\
3158 .RS 4
3159 .\}
3160 .nf
3161 \estartpipeline
3162 SELECT * FROM pg_class;
3163 SELECT 1 \ebind \esendpipeline
3164 \eflushrequest
3165 \egetresults
3166 \eendpipeline
3167 .fi
3168 .if n \{\
3169 .RE
3170 .\}
3171 .sp
3172 .RE
3173 .PP
3174 \et
3175 .RS 4
3176 Toggles the display of output column name headings and row count footer\&. This command is equivalent to
3177 \epset tuples_only
3178 and is provided for convenience\&.
3179 .RE
3180 .PP
3181 \eT \fItable_options\fR
3182 .RS 4
3183 Specifies attributes to be placed within the
3184 table
3185 tag in
3186 HTML
3187 output format\&. This command is equivalent to
3188 \epset tableattr \fItable_options\fR\&.
3189 .RE
3190 .PP
3191 \etiming [ \fIon\fR | \fIoff\fR ]
3192 .RS 4
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\&.
3194 .RE
3195 .PP
3196 \eunrestrict \fIrestrict_key\fR
3197 .RS 4
3198 Exit "restricted" mode (i\&.e\&., where all other meta\-commands are blocked), provided the specified key matches the one given to
3199 \fB\erestrict\fR
3200 when restricted mode was entered\&.
3201 .sp
3202 This command is primarily intended for use in plain\-text dumps generated by
3203 pg_dump,
3204 pg_dumpall, and
3205 pg_restore, but it may be useful elsewhere\&.
3206 .RE
3207 .PP
3208 \eunset \fIname\fR
3209 .RS 4
3210 Unsets (deletes) the
3211 psql
3212 variable
3213 \fIname\fR\&.
3214 .sp
3215 Most variables that control
3216 psql\*(Aqs behavior cannot be unset; instead, an
3217 \eunset
3218 command is interpreted as setting them to their default values\&. See
3219 Variables
3220 below\&.
3221 .RE
3222 .PP
3223 \ew or \ewrite \fIfilename\fR
3224 .br
3225 \ew or \ewrite |\fIcommand\fR
3226 .RS 4
3227 Writes the current query buffer to the file
3228 \fIfilename\fR
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\&.
3231 .sp
3232 If the argument begins with
3233 |, then the entire remainder of the line is taken to be the
3234 \fIcommand\fR
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\&.
3236 .RE
3237 .PP
3238 \ewarn \fItext\fR [ \&.\&.\&. ]
3239 .RS 4
3240 This command is identical to
3241 \fB\eecho\fR
3242 except that the output will be written to
3243 psql\*(Aqs standard error channel, rather than standard output\&.
3244 .RE
3245 .PP
3246 \ewatch [ i[nterval]=\fIseconds\fR ] [ c[ount]=\fItimes\fR ] [ m[in_rows]=\fIrows\fR ] [ \fIseconds\fR ]
3247 .RS 4
3248 Repeatedly execute the current query buffer (as
3249 \eg
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,
3252 \fIseconds\fR
3253 can be specified with or without an
3254 interval=
3255 prefix\&. Each query result is displayed with a header that includes the
3256 \epset title
3257 string (if any), the time as of query start, and the delay interval\&.
3258 .sp
3259 If the current query buffer is empty, the most recently sent query is re\-executed instead\&.
3260 .RE
3261 .PP
3262 \ex [ \fIon\fR | \fIoff\fR | \fIauto\fR ]
3263 .RS 4
3264 Sets or toggles expanded table formatting mode\&. As such it is equivalent to
3265 \epset expanded\&.
3266 .RE
3267 .PP
3268 \ez[Sx] [ \fIpattern\fR ]
3269 .RS 4
3270 Lists tables, views and sequences with their associated access privileges\&. If a
3271 \fIpattern\fR
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
3273 S
3274 modifier to include system objects\&. If
3275 x
3276 is appended to the command name, the results are displayed in expanded mode\&.
3277 .sp
3278 This is an alias for
3279 \fB\edp\fR
3280 (\(lqdisplay privileges\(rq)\&.
3281 .RE
3282 .PP
3283 \e! [ \fIcommand\fR ]
3284 .RS 4
3285 With no argument, escapes to a sub\-shell;
3286 psql
3287 resumes when the sub\-shell exits\&. With an argument, executes the shell command
3288 \fIcommand\fR\&.
3289 .sp
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\&.
3292 .RE
3293 .PP
3294 \e? [ \fItopic\fR ]
3295 .RS 4
3296 Shows help information\&. The optional
3297 \fItopic\fR
3298 parameter (defaulting to
3299 commands) selects which part of
3300 psql
3301 is explained:
3302 commands
3303 describes
3304 psql\*(Aqs backslash commands;
3305 options
3306 describes the command\-line options that can be passed to
3307 psql; and
3308 variables
3309 shows help about
3310 psql
3311 configuration variables\&.
3312 .RE
3313 .PP
3314 \e;
3315 .RS 4
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\&.
3317 .sp
3318 Normally,
3319 psql
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
3321 .sp
3322 .if n \{\
3323 .RS 4
3324 .\}
3325 .nf
3326 select 1; select 2; select 3;
3327 .fi
3328 .if n \{\
3329 .RE
3330 .\}
3331 .sp
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
3333 \e;
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
3335 .sp
3336 .if n \{\
3337 .RS 4
3338 .\}
3339 .nf
3340 select 1\e; select 2\e; select 3;
3341 .fi
3342 .if n \{\
3343 .RE
3344 .\}
3345 .sp
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
3349 Section\ \&54.2.2.1
3350 for more details about how the server handles multi\-query strings\&.)
3351 .RE
3352 .sp
3353 .it 1 an-trap
3354 .nr an-no-space-flag 1
3355 .nr an-break-flag 1
3356 .br
3357 .ps +1
3358 \fBPatterns\fR
3359 .RS 4
3360 .PP
3361 The various
3362 \ed
3363 commands accept a
3364 \fIpattern\fR
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,
3366 \edt FOO
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,
3369 \edt "FOO""BAR"
3370 will display the table named
3371 FOO"BAR
3372 (not
3373 foo"bar)\&. Unlike the normal rules for SQL names, you can put double quotes around just part of a pattern, for instance
3374 \edt FOO"FOO"BAR
3375 will display the table named
3376 fooFOObar\&.
3377 .PP
3378 Whenever the
3379 \fIpattern\fR
3380 parameter is omitted completely, the
3381 \ed
3382 commands display all objects that are visible in the current schema search path \(em this is equivalent to using
3383 *
3384 as the pattern\&. (An object is said to be
3385 visible
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
3387 *\&.*
3388 as the pattern\&.
3389 .PP
3390 Within a pattern,
3391 *
3392 matches any sequence of characters (including no characters) and
3393 ?
3394 matches any single character\&. (This notation is comparable to Unix shell file name patterns\&.) For example,
3395 \edt int*
3396 displays tables whose names begin with
3397 int\&. But within double quotes,
3398 *
3399 and
3400 ?
3401 lose these special meanings and are just matched literally\&.
3402 .PP
3403 A relation pattern that contains a dot (\&.) is interpreted as a schema name pattern followed by an object name pattern\&. For example,
3404 \edt foo*\&.*bar*
3405 displays all tables whose table name includes
3406 bar
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\&.
3409 .PP
3410 A schema pattern that contains a dot (\&.) is interpreted as a database name followed by a schema name pattern\&. For example,
3411 \edn mydb\&.*foo*
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\&.
3414 .PP
3415 Advanced users can use regular\-expression notations such as character classes, for example
3416 [0\-9]
3417 to match any digit\&. All regular expression special characters work as specified in
3418 Section\ \&9.7.3, except for
3419 \&.
3420 which is taken as a separator as mentioned above,
3421 *
3422 which is translated to the regular\-expression notation
3423 \&.*,
3424 ?
3425 which is translated to
3426 \&., and
3427 $
3428 which is matched literally\&. You can emulate these pattern characters at need by writing
3429 ?
3430 for
3431 \&.,
3432 (\fIR\fR+|)
3433 for
3434 \fIR\fR*, or
3435 (\fIR\fR|)
3436 for
3437 \fIR\fR?\&.
3438 $
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,
3440 $
3441 is automatically appended to your pattern)\&. Write
3442 *
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
3444 \edo)\&.
3445 .RE
3446 .SS "Advanced Features"
3447 .sp
3448 .it 1 an-trap
3449 .nr an-no-space-flag 1
3450 .nr an-break-flag 1
3451 .br
3452 .ps +1
3453 \fBVariables\fR
3454 .RS 4
3455 .PP
3456 psql
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\&.
3458 .PP
3459 To set a variable, use the
3460 psql
3461 meta\-command
3462 \fB\eset\fR\&. For example,
3463 .sp
3464 .if n \{\
3465 .RS 4
3466 .\}
3467 .nf
3468 testdb=> \fB\eset foo bar\fR
3469 .fi
3470 .if n \{\
3471 .RE
3472 .\}
3473 .sp
3474 sets the variable
3475 foo
3476 to the value
3477 bar\&. To retrieve the content of the variable, precede the name with a colon, for example:
3478 .sp
3479 .if n \{\
3480 .RS 4
3481 .\}
3482 .nf
3483 testdb=> \fB\eecho :foo\fR
3484 bar
3485 .fi
3486 .if n \{\
3487 .RE
3488 .\}
3489 .sp
3490 This works in both regular SQL commands and meta\-commands; there is more detail in
3491 SQL Interpolation, below\&.
3492 .PP
3493 If you call
3494 \fB\eset\fR
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
3497 \fB\eset\fR
3498 without any argument\&.
3499 .if n \{\
3500 .sp
3501 .\}
3502 .RS 4
3503 .it 1 an-trap
3504 .nr an-no-space-flag 1
3505 .nr an-break-flag 1
3506 .br
3507 .ps +1
3508 \fBNote\fR
3509 .ps -1
3510 .br
3511 .PP
3512 The arguments of
3513 \fB\eset\fR
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
3516 and get
3517 \(lqsoft links\(rq
3518 or
3519 \(lqvariable variables\(rq
3520 of
3521 Perl
3522 or
3523 PHP
3524 fame, respectively\&. Unfortunately (or fortunately?), there is no way to do anything useful with these constructs\&. On the other hand,
3525 \eset bar :foo
3526 is a perfectly valid way to copy a variable\&.
3527 .sp .5v
3528 .RE
3529 .PP
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\&.
3533 .PP
3534 Variables that control
3535 psql\*(Aqs behavior generally cannot be unset or set to invalid values\&. An
3536 \eunset
3537 command is allowed but is interpreted as setting the variable to its default value\&. A
3538 \eset
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
3541 on
3542 and
3543 off
3544 will also accept other common spellings of Boolean values, such as
3545 true
3546 and
3547 false\&.
3548 .PP
3549 The specially treated variables are:
3550 .PP
3551 \fIAUTOCOMMIT\fR
3552 .RS 4
3553 When
3554 on
3555 (the default), each SQL command is automatically committed upon successful completion\&. To postpone commit in this mode, you must enter a
3556 \fBBEGIN\fR
3557 or
3558 \fBSTART TRANSACTION\fR
3559 SQL command\&. When
3560 off
3561 or unset, SQL commands are not committed until you explicitly issue
3562 \fBCOMMIT\fR
3563 or
3564 \fBEND\fR\&. The autocommit\-off mode works by issuing an implicit
3565 \fBBEGIN\fR
3566 for you, just before any command that is not already in a transaction block and is not itself a
3567 \fBBEGIN\fR
3568 or other transaction\-control command, nor a command that cannot be executed inside a transaction block (such as
3569 \fBVACUUM\fR)\&.
3570 .if n \{\
3571 .sp
3572 .\}
3573 .RS 4
3574 .it 1 an-trap
3575 .nr an-no-space-flag 1
3576 .nr an-break-flag 1
3577 .br
3578 .ps +1
3579 \fBNote\fR
3580 .ps -1
3581 .br
3582 In autocommit\-off mode, you must explicitly abandon any failed transaction by entering
3583 \fBABORT\fR
3584 or
3585 \fBROLLBACK\fR\&. Also keep in mind that if you exit the session without committing, your work will be lost\&.
3586 .sp .5v
3587 .RE
3588 .if n \{\
3589 .sp
3590 .\}
3591 .RS 4
3592 .it 1 an-trap
3593 .nr an-no-space-flag 1
3594 .nr an-break-flag 1
3595 .br
3596 .ps +1
3597 \fBNote\fR
3598 .ps -1
3599 .br
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
3602 psqlrc
3603 file or your
3604 ~/\&.psqlrc
3605 file\&.
3606 .sp .5v
3607 .RE
3608 .RE
3609 .PP
3610 \fICOMP_KEYWORD_CASE\fR
3611 .RS 4
3612 Determines which letter case to use when completing an SQL key word\&. If set to
3613 lower
3614 or
3615 upper, the completed word will be in lower or upper case, respectively\&. If set to
3616 preserve\-lower
3617 or
3618 preserve\-upper
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\&.
3620 .RE
3621 .PP
3622 \fIDBNAME\fR
3623 .RS 4
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\&.
3625 .RE
3626 .PP
3627 \fIECHO\fR
3628 .RS 4
3629 If set to
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
3632 queries,
3633 psql
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
3638 none
3639 (the default), then no queries are displayed\&.
3640 .RE
3641 .PP
3642 \fIECHO_HIDDEN\fR
3643 .RS 4
3644 When this variable is set to
3645 on
3646 and a backslash command queries the database, the query is first shown\&. This feature helps you to study
3647 PostgreSQL
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
3651 off\&.
3652 .RE
3653 .PP
3654 \fIENCODING\fR
3655 .RS 4
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\&.
3658 .RE
3659 .PP
3660 \fIERROR\fR
3661 .RS 4
3662 true
3663 if the last SQL query failed,
3664 false
3665 if it succeeded\&. See also
3666 \fISQLSTATE\fR\&.
3667 .RE
3668 .PP
3669 \fIFETCH_COUNT\fR
3670 .RS 4
3671 If this variable is set to an integer value greater than zero, the results of
3672 \fBSELECT\fR
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\&.
3674 .if n \{\
3675 .sp
3676 .\}
3677 .RS 4
3678 .it 1 an-trap
3679 .nr an-no-space-flag 1
3680 .nr an-break-flag 1
3681 .br
3682 .ps +1
3683 \fBTip\fR
3684 .ps -1
3685 .br
3686 Although you can use any output format with this feature, the default
3687 aligned
3688 format tends to look bad because each group of
3689 \fIFETCH_COUNT\fR
3690 rows will be formatted separately, leading to varying column widths across the row groups\&. The other output formats work better\&.
3691 .sp .5v
3692 .RE
3693 .RE
3694 .PP
3695 \fIHIDE_TABLEAM\fR
3696 .RS 4
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\&.
3699 .RE
3700 .PP
3701 \fIHIDE_TOAST_COMPRESSION\fR
3702 .RS 4
3703 If this variable is set to
3704 true, column compression method details are not displayed\&. This is mainly useful for regression tests\&.
3705 .RE
3706 .PP
3707 \fIHISTCONTROL\fR
3708 .RS 4
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
3712 ignoreboth
3713 combines the two options\&. If set to
3714 none
3715 (the default), all lines read in interactive mode are saved on the history list\&.
3716 .if n \{\
3717 .sp
3718 .\}
3719 .RS 4
3720 .it 1 an-trap
3721 .nr an-no-space-flag 1
3722 .nr an-break-flag 1
3723 .br
3724 .ps +1
3725 \fBNote\fR
3726 .ps -1
3727 .br
3728 This feature was shamelessly plagiarized from
3729 Bash\&.
3730 .sp .5v
3731 .RE
3732 .RE
3733 .PP
3734 \fIHISTFILE\fR
3735 .RS 4
3736 The file name that will be used to store the history list\&. If unset, the file name is taken from the
3737 \fBPSQL_HISTORY\fR
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:
3742 .sp
3743 .if n \{\
3744 .RS 4
3745 .\}
3746 .nf
3747 \eset HISTFILE ~/\&.psql_history\-:DBNAME
3748 .fi
3749 .if n \{\
3750 .RE
3751 .\}
3752 .sp
3753 in
3754 ~/\&.psqlrc
3755 will cause
3756 psql
3757 to maintain a separate history for each database\&.
3758 .if n \{\
3759 .sp
3760 .\}
3761 .RS 4
3762 .it 1 an-trap
3763 .nr an-no-space-flag 1
3764 .nr an-break-flag 1
3765 .br
3766 .ps +1
3767 \fBNote\fR
3768 .ps -1
3769 .br
3770 This feature was shamelessly plagiarized from
3771 Bash\&.
3772 .sp .5v
3773 .RE
3774 .RE
3775 .PP
3776 \fIHISTSIZE\fR
3777 .RS 4
3778 The maximum number of commands to store in the command history (default 500)\&. If set to a negative value, no limit is applied\&.
3779 .if n \{\
3780 .sp
3781 .\}
3782 .RS 4
3783 .it 1 an-trap
3784 .nr an-no-space-flag 1
3785 .nr an-break-flag 1
3786 .br
3787 .ps +1
3788 \fBNote\fR
3789 .ps -1
3790 .br
3791 This feature was shamelessly plagiarized from
3792 Bash\&.
3793 .sp .5v
3794 .RE
3795 .RE
3796 .PP
3797 \fIHOST\fR
3798 .RS 4
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\&.
3800 .RE
3801 .PP
3802 \fIIGNOREEOF\fR
3803 .RS 4
3804 If set to 1 or less, sending an
3805 EOF
3806 character (usually
3807 Control+D) to an interactive session of
3808 psql
3809 will terminate the application\&. If set to a larger numeric value, that many consecutive
3810 EOF
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\&.
3812 .if n \{\
3813 .sp
3814 .\}
3815 .RS 4
3816 .it 1 an-trap
3817 .nr an-no-space-flag 1
3818 .nr an-break-flag 1
3819 .br
3820 .ps +1
3821 \fBNote\fR
3822 .ps -1
3823 .br
3824 This feature was shamelessly plagiarized from
3825 Bash\&.
3826 .sp .5v
3827 .RE
3828 .RE
3829 .PP
3830 \fILASTOID\fR
3831 .RS 4
3832 The value of the last affected OID, as returned from an
3833 \fBINSERT\fR
3834 or
3835 \fB\elo_import\fR
3836 command\&. This variable is only guaranteed to be valid until after the result of the next
3837 SQL
3838 command has been displayed\&.
3839 PostgreSQL
3840 servers since version 12 do not support OID system columns anymore, thus LASTOID will always be 0 following
3841 \fBINSERT\fR
3842 when targeting such servers\&.
3843 .RE
3844 .PP
3845 \fILAST_ERROR_MESSAGE\fR
3846 .br
3847 \fILAST_ERROR_SQLSTATE\fR
3848 .RS 4
3849 The primary error message and associated SQLSTATE code for the most recent failed query in the current
3850 psql
3851 session, or an empty string and
3852 00000
3853 if no error has occurred in the current session\&.
3854 .RE
3855 .PP
3856 \fION_ERROR_ROLLBACK\fR
3857 .RS 4
3858 When set to
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
3861 off
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
3863 \fBSAVEPOINT\fR
3864 for you, just before each command that is in a transaction block, and then rolling back to the savepoint if the command fails\&.
3865 .RE
3866 .PP
3867 \fION_ERROR_STOP\fR
3868 .RS 4
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,
3871 psql
3872 will return to the command prompt; otherwise,
3873 psql
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\&.
3875 .RE
3876 .PP
3877 \fIPIPELINE_COMMAND_COUNT\fR
3878 .RS 4
3879 The number of commands queued in an ongoing pipeline\&.
3880 .RE
3881 .PP
3882 \fIPIPELINE_RESULT_COUNT\fR
3883 .RS 4
3884 The number of commands of an ongoing pipeline that were followed by either a
3885 \fB\eflushrequest\fR
3886 or a
3887 \fB\esyncpipeline\fR, forcing the server to send the results\&. These results can be retrieved with
3888 \fB\egetresults\fR\&.
3889 .RE
3890 .PP
3891 \fIPIPELINE_SYNC_COUNT\fR
3892 .RS 4
3893 The number of sync messages queued in an ongoing pipeline\&.
3894 .RE
3895 .PP
3896 \fIPORT\fR
3897 .RS 4
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\&.
3899 .RE
3900 .PP
3901 \fIPROMPT1\fR
3902 .br
3903 \fIPROMPT2\fR
3904 .br
3905 \fIPROMPT3\fR
3906 .RS 4
3907 These specify what the prompts
3908 psql
3909 issues should look like\&. See
3910 Prompting
3911 below\&.
3912 .RE
3913 .PP
3914 \fIQUIET\fR
3915 .RS 4
3916 Setting this variable to
3917 on
3918 is equivalent to the command line option
3919 \fB\-q\fR\&. It is probably not too useful in interactive mode\&.
3920 .RE
3921 .PP
3922 \fIROW_COUNT\fR
3923 .RS 4
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\&.
3925 .RE
3926 .PP
3927 \fISERVER_VERSION_NAME\fR
3928 .br
3929 \fISERVER_VERSION_NUM\fR
3930 .RS 4
3931 The server\*(Aqs version number as a string, for example
3932 9\&.6\&.2,
3933 10\&.1
3934 or
3935 11beta1, and in numeric form, for example
3936 90602
3937 or
3938 100001\&. These are set every time you connect to a database (including program start\-up), but can be changed or unset\&.
3939 .RE
3940 .PP
3941 \fISERVICE\fR
3942 .RS 4
3943 The service name, if applicable\&.
3944 .RE
3945 .PP
3946 \fISHELL_ERROR\fR
3947 .RS 4
3948 true
3949 if the last shell command failed,
3950 false
3951 if it succeeded\&. This applies to shell commands invoked via the
3952 \e!,
3953 \eg,
3954 \eo,
3955 \ew, and
3956 \ecopy
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
3959 \eo
3960 command\&. See also
3961 \fISHELL_EXIT_CODE\fR\&.
3962 .RE
3963 .PP
3964 \fISHELL_EXIT_CODE\fR
3965 .RS 4
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
3967 \e!,
3968 \eg,
3969 \eo,
3970 \ew, and
3971 \ecopy
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
3974 \eo
3975 command\&. See also
3976 \fISHELL_ERROR\fR\&.
3977 .RE
3978 .PP
3979 \fISHOW_ALL_RESULTS\fR
3980 .RS 4
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
3984 psql\&.
3985 .RE
3986 .PP
3987 \fISHOW_CONTEXT\fR
3988 .RS 4
3989 This variable can be set to the values
3990 never,
3991 errors, or
3992 always
3993 to control whether
3994 CONTEXT
3995 fields are displayed in messages from the server\&. The default is
3996 errors
3997 (meaning that context will be shown in error messages, but not in notice or warning messages)\&. This setting has no effect when
3998 \fIVERBOSITY\fR
3999 is set to
4000 terse
4001 or
4002 sqlstate\&. (See also
4003 \fB\eerrverbose\fR, for use when you want a verbose version of the error you just got\&.)
4004 .RE
4005 .PP
4006 \fISINGLELINE\fR
4007 .RS 4
4008 Setting this variable to
4009 on
4010 is equivalent to the command line option
4011 \fB\-S\fR\&.
4012 .RE
4013 .PP
4014 \fISINGLESTEP\fR
4015 .RS 4
4016 Setting this variable to
4017 on
4018 is equivalent to the command line option
4019 \fB\-s\fR\&.
4020 .RE
4021 .PP
4022 \fISQLSTATE\fR
4023 .RS 4
4024 The error code (see
4025 Appendix\ \&A) associated with the last SQL query\*(Aqs failure, or
4026 00000
4027 if it succeeded\&.
4028 .RE
4029 .PP
4030 \fIUSER\fR
4031 .RS 4
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\&.
4033 .RE
4034 .PP
4035 \fIVERBOSITY\fR
4036 .RS 4
4037 This variable can be set to the values
4038 default,
4039 verbose,
4040 terse, or
4041 sqlstate
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\&.)
4044 .RE
4045 .PP
4046 \fIVERSION\fR
4047 .br
4048 \fIVERSION_NAME\fR
4049 .br
4050 \fIVERSION_NUM\fR
4051 .RS 4
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\&.,
4054 9\&.6\&.2,
4055 10\&.1, or
4056 11beta1), and a number (e\&.g\&.,
4057 90602
4058 or
4059 100001)\&. They can be changed or unset\&.
4060 .RE
4061 .PP
4062 \fIWATCH_INTERVAL\fR
4063 .RS 4
4064 This variable sets the default interval, in seconds, which
4065 \fB\ewatch\fR
4066 waits between executing the query\&. The default is 2 seconds\&. Specifying an interval in the command overrides this variable\&.
4067 .RE
4068 .RE
4069 .sp
4070 .it 1 an-trap
4071 .nr an-no-space-flag 1
4072 .nr an-break-flag 1
4073 .br
4074 .ps +1
4075 \fBSQL Interpolation\fR
4076 .RS 4
4077 .PP
4078 A key feature of
4079 psql
4080 variables is that you can substitute (\(lqinterpolate\(rq) them into regular
4081 SQL
4082 statements, as well as the arguments of meta\-commands\&. Furthermore,
4083 psql
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,
4085 .sp
4086 .if n \{\
4087 .RS 4
4088 .\}
4089 .nf
4090 testdb=> \fB\eset foo \*(Aqmy_table\*(Aq\fR
4091 testdb=> \fBSELECT * FROM :foo;\fR
4092 .fi
4093 .if n \{\
4094 .RE
4095 .\}
4096 .sp
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\&.
4099 .PP
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:
4101 .sp
4102 .if n \{\
4103 .RS 4
4104 .\}
4105 .nf
4106 testdb=> \fB\eset foo \*(Aqmy_table\*(Aq\fR
4107 testdb=> \fBSELECT * FROM :"foo";\fR
4108 .fi
4109 .if n \{\
4110 .RE
4111 .\}
4112 .PP
4113 Variable interpolation will not be performed within quoted
4114 SQL
4115 literals and identifiers\&. Therefore, a construction such as
4116 \*(Aq:foo\*(Aq
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)\&.
4118 .PP
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:
4120 .sp
4121 .if n \{\
4122 .RS 4
4123 .\}
4124 .nf
4125 testdb=> \fB\eset content `cat my_file\&.txt`\fR
4126 testdb=> \fBINSERT INTO my_table VALUES (:\*(Aqcontent\*(Aq);\fR
4127 .fi
4128 .if n \{\
4129 .RE
4130 .\}
4131 .sp
4132 (Note that this still won\*(Aqt work if
4133 my_file\&.txt
4134 contains NUL bytes\&.
4135 psql
4136 does not support embedded NUL bytes in variable values\&.)
4137 .PP
4138 Since colons can legally appear in SQL commands, an apparent attempt at interpolation (that is,
4139 :name,
4140 :\*(Aqname\*(Aq, or
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\&.
4142 .PP
4143 The
4144 :{?\fIname\fR}
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\&.
4146 .PP
4147 The colon syntax for variables is standard
4148 SQL
4149 for embedded query languages, such as
4150 ECPG\&. The colon syntaxes for array slices and type casts are
4151 PostgreSQL
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
4153 psql
4154 extension\&.
4155 .RE
4156 .sp
4157 .it 1 an-trap
4158 .nr an-no-space-flag 1
4159 .nr an-break-flag 1
4160 .br
4161 .ps +1
4162 \fBPrompting\fR
4163 .RS 4
4164 .PP
4165 The prompts
4166 psql
4167 issues can be customized to your preference\&. The three variables
4168 \fIPROMPT1\fR,
4169 \fIPROMPT2\fR, and
4170 \fIPROMPT3\fR
4171 contain strings and special escape sequences that describe the appearance of the prompt\&. Prompt 1 is the normal prompt that is issued when
4172 psql
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
4174 SQL
4175 \fBCOPY FROM STDIN\fR
4176 command and you need to type in a row value on the terminal\&.
4177 .PP
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:
4179 .PP
4180 %M
4181 .RS 4
4182 The full host name (with domain name) of the database server, or
4183 [local]
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\&.
4186 .RE
4187 .PP
4188 %m
4189 .RS 4
4190 The host name of the database server, truncated at the first dot, or
4191 [local]
4192 if the connection is over a Unix domain socket\&.
4193 .RE
4194 .PP
4195 %>
4196 .RS 4
4197 The port number at which the database server is listening\&.
4198 .RE
4199 .PP
4200 %n
4201 .RS 4
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\&.)
4204 .RE
4205 .PP
4206 %s
4207 .RS 4
4208 The name of the service\&.
4209 .RE
4210 .PP
4211 %/
4212 .RS 4
4213 The name of the current database\&.
4214 .RE
4215 .PP
4216 %~
4217 .RS 4
4218 Like
4219 %/, but the output is
4220 ~
4221 (tilde) if the database is your default database\&.
4222 .RE
4223 .PP
4224 %#
4225 .RS 4
4226 If the session user is a database superuser, then a
4227 #, otherwise a
4228 >\&. (The expansion of this value might change during a database session as the result of the command
4229 \fBSET SESSION AUTHORIZATION\fR\&.)
4230 .RE
4231 .PP
4232 %p
4233 .RS 4
4234 The process ID of the backend currently connected to\&.
4235 .RE
4236 .PP
4237 %P
4238 .RS 4
4239 Pipeline status:
4240 off
4241 when not in a pipeline,
4242 on
4243 when in an ongoing pipeline or
4244 abort
4245 when in an aborted pipeline\&.
4246 .RE
4247 .PP
4248 %R
4249 .RS 4
4250 In prompt 1 normally
4251 =, but
4252 @
4253 if the session is in an inactive branch of a conditional block, or
4254 ^
4255 if in single\-line mode, or
4256 !
4257 if the session is disconnected from the database (which can happen if
4258 \fB\econnect\fR
4259 fails)\&. In prompt 2
4260 %R
4261 is replaced by a character that depends on why
4262 psql
4263 expects more input:
4264 \-
4265 if the command simply wasn\*(Aqt terminated yet, but
4266 *
4267 if there is an unfinished
4268 /* \&.\&.\&. */
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
4270 (
4271 if there is an unmatched left parenthesis\&. In prompt 3
4272 %R
4273 doesn\*(Aqt produce anything\&.
4274 .RE
4275 .PP
4276 %x
4277 .RS 4
4278 Transaction status: an empty string when not in a transaction block, or
4279 *
4280 when in a transaction block, or
4281 !
4282 when in a failed transaction block, or
4283 ?
4284 when the transaction state is indeterminate (for example, because there is no connection)\&.
4285 .RE
4286 .PP
4287 %l
4288 .RS 4
4289 The line number inside the current statement, starting from
4290 1\&.
4291 .RE
4292 .PP
4293 %\fIdigits\fR
4294 .RS 4
4295 The character with the indicated octal code is substituted\&.
4296 .RE
4297 .PP
4298 %:\fIname\fR:
4299 .RS 4
4300 The value of the
4301 psql
4302 variable
4303 \fIname\fR\&. See
4304 Variables, above, for details\&.
4305 .RE
4306 .PP
4307 %`\fIcommand\fR`
4308 .RS 4
4309 The output of
4310 \fIcommand\fR, similar to ordinary
4311 \(lqback\-tick\(rq
4312 substitution\&.
4313 .RE
4314 .PP
4315 %[ \&.\&.\&. %]
4316 .RS 4
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
4318 Readline
4319 to work properly, these non\-printing control characters must be designated as invisible by surrounding them with
4320 %[
4321 and
4322 %]\&. Multiple pairs of these can occur within the prompt\&. For example:
4323 .sp
4324 .if n \{\
4325 .RS 4
4326 .\}
4327 .nf
4328 testdb=> \eset PROMPT1 \*(Aq%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# \*(Aq
4329 .fi
4330 .if n \{\
4331 .RE
4332 .\}
4333 .sp
4334 results in a boldfaced (1;) yellow\-on\-black (33;40) prompt on VT100\-compatible, color\-capable terminals\&.
4335 .RE
4336 .PP
4337 %w
4338 .RS 4
4339 Whitespace of the same width as the most recent output of
4340 \fIPROMPT1\fR\&. This can be used as a
4341 \fIPROMPT2\fR
4342 setting, so that multi\-line statements are aligned with the first line, but there is no visible secondary prompt\&.
4343 .RE
4344 To insert a percent sign into your prompt, write
4345 %%\&. The default prompts are
4346 \*(Aq%/%R%x%# \*(Aq
4347 for prompts 1 and 2, and
4348 \*(Aq>> \*(Aq
4349 for prompt 3\&.
4350 .if n \{\
4351 .sp
4352 .\}
4353 .RS 4
4354 .it 1 an-trap
4355 .nr an-no-space-flag 1
4356 .nr an-break-flag 1
4357 .br
4358 .ps +1
4359 \fBNote\fR
4360 .ps -1
4361 .br
4362 .PP
4363 This feature was shamelessly plagiarized from
4364 tcsh\&.
4365 .sp .5v
4366 .RE
4367 .RE
4368 .sp
4369 .it 1 an-trap
4370 .nr an-no-space-flag 1
4371 .nr an-break-flag 1
4372 .br
4373 .ps +1
4374 \fBCommand-Line Editing\fR
4375 .RS 4
4376 .PP
4377 psql
4378 uses the
4379 Readline
4380 or
4381 libedit
4382 library, if available, for convenient line editing and retrieval\&. The command history is automatically saved when
4383 psql
4384 exits and is reloaded when
4385 psql
4386 starts up\&. Type up\-arrow or control\-P to retrieve previous lines\&.
4387 .PP
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
4389 ins
4390 and pressing TAB will fill in
4391 insert into\&. Then, typing a few characters of a table or schema name and pressing
4392 TAB
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
4394 TAB
4395 more than once to get a menu\&.)
4396 .PP
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
4398 \fBBEGIN\fR
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
4402 \&.inputrc
4403 in your home directory:
4404 .sp
4405 .if n \{\
4406 .RS 4
4407 .\}
4408 .nf
4409 $if psql
4410 set disable\-completion on
4411 $endif
4412 .fi
4413 .if n \{\
4414 .RE
4415 .\}
4416 .sp
4417 (This is not a
4418 psql
4419 but a
4420 Readline
4421 feature\&. Read its documentation for further details\&.)
4422 .PP
4423 The
4424 \fB\-n\fR
4425 (\fB\-\-no\-readline\fR) command line option can also be useful to disable use of
4426 Readline
4427 for a single run 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
4429 TAB
4430 characters\&.
4431 .RE
4432 .SH "ENVIRONMENT"
4433 .PP
4434 \fBCOLUMNS\fR
4435 .RS 4
4436 If
4437 \epset columns
4438 is zero, controls the width for the
4439 wrapped
4440 format and width for determining if wide output requires the pager or should be switched to the vertical format in expanded auto mode\&.
4441 .RE
4442 .PP
4443 \fBPGDATABASE\fR
4444 .br
4445 \fBPGHOST\fR
4446 .br
4447 \fBPGPORT\fR
4448 .br
4449 \fBPGUSER\fR
4450 .RS 4
4451 Default connection parameters (see
4452 Section\ \&32.15)\&.
4453 .RE
4454 .PP
4455 \fBPG_COLOR\fR
4456 .RS 4
4457 Specifies whether to use color in diagnostic messages\&. Possible values are
4458 always,
4459 auto
4460 and
4461 never\&.
4462 .RE
4463 .PP
4464 \fBPSQL_EDITOR\fR
4465 .br
4466 \fBEDITOR\fR
4467 .br
4468 \fBVISUAL\fR
4469 .RS 4
4470 Editor used by the
4471 \fB\ee\fR,
4472 \fB\eef\fR, and
4473 \fB\eev\fR
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
4475 vi
4476 on Unix systems or
4477 notepad\&.exe
4478 on Windows systems\&.
4479 .RE
4480 .PP
4481 \fBPSQL_EDITOR_LINENUMBER_ARG\fR
4482 .RS 4
4483 When
4484 \fB\ee\fR,
4485 \fB\eef\fR, or
4486 \fB\eev\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
4488 Emacs
4489 or
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:
4491 .sp
4492 .if n \{\
4493 .RS 4
4494 .\}
4495 .nf
4496 PSQL_EDITOR_LINENUMBER_ARG=\*(Aq+\*(Aq
4497 PSQL_EDITOR_LINENUMBER_ARG=\*(Aq\-\-line \*(Aq
4498 .fi
4499 .if n \{\
4500 .RE
4501 .\}
4502 .sp
4503 The default is
4504 +
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\&.
4507 .RE
4508 .PP
4509 \fBPSQL_HISTORY\fR
4510 .RS 4
4511 Alternative location for the command history file\&. Tilde (~) expansion is performed\&.
4512 .RE
4513 .PP
4514 \fBPSQL_PAGER\fR
4515 .br
4516 \fBPAGER\fR
4517 .RS 4
4518 If a query\*(Aqs results do not fit on the screen, they are piped through this command\&. Typical values are
4519 more
4520 or
4521 less\&. Use of the pager can be disabled by setting
4522 \fBPSQL_PAGER\fR
4523 or
4524 \fBPAGER\fR
4525 to an empty string, or by adjusting the pager\-related options of the
4526 \fB\epset\fR
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
4528 more
4529 on most platforms, but
4530 less
4531 on Cygwin\&.
4532 .RE
4533 .PP
4534 \fBPSQL_WATCH_PAGER\fR
4535 .RS 4
4536 When a query is executed repeatedly with the
4537 \fB\ewatch\fR
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
4541 pspg
4542 pager (not part of
4543 PostgreSQL
4544 but available in many open source software distributions) can display the output of
4545 \fB\ewatch\fR
4546 if started with the option
4547 \-\-stream\&.
4548 .RE
4549 .PP
4550 \fBPSQLRC\fR
4551 .RS 4
4552 Alternative location of the user\*(Aqs
4553 \&.psqlrc
4554 file\&. Tilde (~) expansion is performed\&.
4555 .RE
4556 .PP
4557 \fBSHELL\fR
4558 .RS 4
4559 Command executed by the
4560 \fB\e!\fR
4561 command\&.
4562 .RE
4563 .PP
4564 \fBTMPDIR\fR
4565 .RS 4
4566 Directory for storing temporary files\&. The default is
4567 /tmp\&.
4568 .RE
4569 .PP
4570 This utility, like most other
4571 PostgreSQL
4572 utilities, also uses the environment variables supported by
4573 libpq
4574 (see
4575 Section\ \&32.15)\&.
4576 .SH "FILES"
4577 .PP
4578 psqlrc and ~/\&.psqlrc
4579 .RS 4
4580 Unless it is passed an
4581 \fB\-X\fR
4582 option,
4583 psql
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
4585 \fB\eset\fR
4586 and
4587 \fBSET\fR
4588 commands\&.
4589 .sp
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
4595 \&.\&./etc/
4596 relative to the directory containing the
4597 PostgreSQL
4598 executables\&. The directory to look in can be set explicitly via the
4599 \fBPGSYSCONFDIR\fR
4600 environment variable\&.
4601 .sp
4602 The user\*(Aqs personal startup file is named
4603 \&.psqlrc
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
4606 \fBPSQLRC\fR
4607 environment variable\&.
4608 .sp
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
4611 PostgreSQL
4612 major or minor release identifier to the file name, for example
4613 ~/\&.psqlrc\-18
4614 or
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\&.
4616 .RE
4617 .PP
4618 \&.psql_history
4619 .RS 4
4620 The command\-line history is stored in the file
4621 ~/\&.psql_history, or
4622 %APPDATA%\epostgresql\epsql_history
4623 on Windows\&.
4624 .sp
4625 The location of the history file can be set explicitly via the
4626 \fIHISTFILE\fR
4627 psql
4628 variable or the
4629 \fBPSQL_HISTORY\fR
4630 environment variable\&.
4631 .RE
4632 .SH "NOTES"
4633 .sp
4634 .RS 4
4635 .ie n \{\
4636 \h'-04'\(bu\h'+03'\c
4637 .\}
4638 .el \{\
4639 .sp -1
4640 .IP \(bu 2.3
4641 .\}
4642 psql
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
4644 psql
4645 itself\&. However, backslash commands of the
4646 \ed
4647 family should work with servers of versions back to 9\&.2, though not necessarily with servers newer than
4648 psql
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\&.
4650 .sp
4651 If you want to use
4652 psql
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
4655 psql
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\&.
4657 .RE
4658 .sp
4659 .RS 4
4660 .ie n \{\
4661 \h'-04'\(bu\h'+03'\c
4662 .\}
4663 .el \{\
4664 .sp -1
4665 .IP \(bu 2.3
4666 .\}
4667 Before
4668 PostgreSQL
4669 9\&.6, the
4670 \fB\-c\fR
4671 option implied
4672 \fB\-X\fR
4673 (\fB\-\-no\-psqlrc\fR); this is no longer the case\&.
4674 .RE
4675 .sp
4676 .RS 4
4677 .ie n \{\
4678 \h'-04'\(bu\h'+03'\c
4679 .\}
4680 .el \{\
4681 .sp -1
4682 .IP \(bu 2.3
4683 .\}
4684 Before
4685 PostgreSQL
4686 8\&.4,
4687 psql
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\&.
4689 .RE
4690 .SH "NOTES FOR WINDOWS USERS"
4691 .PP
4692 psql
4693 is built as a
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
4695 psql\&. If
4696 psql
4697 detects a problematic console code page, it will warn you at startup\&. To change the console code page, two things are necessary:
4698 .sp
4699 .RS 4
4700 .ie n \{\
4701 \h'-04'\(bu\h'+03'\c
4702 .\}
4703 .el \{\
4704 .sp -1
4705 .IP \(bu 2.3
4706 .\}
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
4709 /etc/profile\&.
4710 .RE
4711 .sp
4712 .RS 4
4713 .ie n \{\
4714 \h'-04'\(bu\h'+03'\c
4715 .\}
4716 .el \{\
4717 .sp -1
4718 .IP \(bu 2.3
4719 .\}
4720 Set the console font to
4721 Lucida Console, because the raster font does not work with the ANSI code page\&.
4722 .RE
4723 .SH "EXAMPLES"
4724 .PP
4725 The first example shows how to spread a command over several lines of input\&. Notice the changing prompt:
4726 .sp
4727 .if n \{\
4728 .RS 4
4729 .\}
4730 .nf
4731 testdb=> \fBCREATE TABLE my_table (\fR
4732 testdb(> \fB first integer not null default 0,\fR
4733 testdb(> \fB second text)\fR
4734 testdb\-> \fB;\fR
4735 CREATE TABLE
4736 .fi
4737 .if n \{\
4738 .RE
4739 .\}
4740 .sp
4741 Now look at the table definition again:
4742 .sp
4743 .if n \{\
4744 .RS 4
4745 .\}
4746 .nf
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
4752  second | text    |           |          |
4753 .fi
4754 .if n \{\
4755 .RE
4756 .\}
4757 .sp
4758 Now we change the prompt to something more interesting:
4759 .sp
4760 .if n \{\
4761 .RS 4
4762 .\}
4763 .nf
4764 testdb=> \fB\eset PROMPT1 \*(Aq%n@%m %~%R%# \*(Aq\fR
4765 peter@localhost testdb=>
4766 .fi
4767 .if n \{\
4768 .RE
4769 .\}
4770 .sp
4771 Let\*(Aqs assume you have filled the table with data and want to take a look at it:
4772 .sp
4773 .if n \{\
4774 .RS 4
4775 .\}
4776 .nf
4777 peter@localhost testdb=> SELECT * FROM my_table;
4778  first | second
4779 \-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-
4780      1 | one
4781      2 | two
4782      3 | three
4783      4 | four
4784 (4 rows)
4785 .fi
4786 .if n \{\
4787 .RE
4788 .\}
4789 .sp
4790 You can display tables in different ways by using the
4791 \fB\epset\fR
4792 command:
4793 .sp
4794 .if n \{\
4795 .RS 4
4796 .\}
4797 .nf
4798 peter@localhost testdb=> \fB\epset border 2\fR
4799 Border style is 2\&.
4800 peter@localhost testdb=> \fBSELECT * FROM my_table;\fR
4801 +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+
4802 | first | second |
4803 +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+
4804 |     1 | one    |
4805 |     2 | two    |
4806 |     3 | three  |
4807 |     4 | four   |
4808 +\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+
4809 (4 rows)
4810
4811 peter@localhost testdb=> \fB\epset border 0\fR
4812 Border style is 0\&.
4813 peter@localhost testdb=> \fBSELECT * FROM my_table;\fR
4814 first second
4815 \-\-\-\-\- \-\-\-\-\-\-
4816     1 one
4817     2 two
4818     3 three
4819     4 four
4820 (4 rows)
4821
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
4829 one,1
4830 two,2
4831 three,3
4832 four,4
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
4838 one     1
4839 two     2
4840 three   3
4841 four    4
4842 .fi
4843 .if n \{\
4844 .RE
4845 .\}
4846 .sp
4847 Alternatively, use the short commands:
4848 .sp
4849 .if n \{\
4850 .RS 4
4851 .\}
4852 .nf
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
4858 \-[ RECORD 1 ]\-
4859 first  | 1
4860 second | one
4861 \-[ RECORD 2 ]\-
4862 first  | 2
4863 second | two
4864 \-[ RECORD 3 ]\-
4865 first  | 3
4866 second | three
4867 \-[ RECORD 4 ]\-
4868 first  | 4
4869 second | four
4870 .fi
4871 .if n \{\
4872 .RE
4873 .\}
4874 .PP
4875 Also, these output format options can be set for just one query by using
4876 \eg:
4877 .sp
4878 .if n \{\
4879 .RS 4
4880 .\}
4881 .nf
4882 peter@localhost testdb=> \fBSELECT * FROM my_table\fR
4883 peter@localhost testdb\-> \fB\eg (format=aligned tuples_only=off expanded=on)\fR
4884 \-[ RECORD 1 ]\-
4885 first  | 1
4886 second | one
4887 \-[ RECORD 2 ]\-
4888 first  | 2
4889 second | two
4890 \-[ RECORD 3 ]\-
4891 first  | 3
4892 second | three
4893 \-[ RECORD 4 ]\-
4894 first  | 4
4895 second | four
4896 .fi
4897 .if n \{\
4898 .RE
4899 .\}
4900 .PP
4901 Here is an example of using the
4902 \fB\edf\fR
4903 command to find only functions with names matching
4904 int*pl
4905 and whose second argument is of type
4906 bigint:
4907 .sp
4908 .if n \{\
4909 .RS 4
4910 .\}
4911 .nf
4912 testdb=> \fB\edf int*pl * bigint\fR
4913                           List of functions
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
4919 (3 rows)
4920 .fi
4921 .if n \{\
4922 .RE
4923 .\}
4924 .PP
4925 Here, the
4926 +
4927 option is used to display additional information about one of these functions, and
4928 x
4929 is used to display the results in expanded mode:
4930 .sp
4931 .if n \{\
4932 .RS 4
4933 .\}
4934 .nf
4935 testdb=> \fB\edf+x int*pl integer bigint\fR
4936 List of functions
4937 \-[ RECORD 1 ]\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
4938 Schema              | pg_catalog
4939 Name                | int48pl
4940 Result data type    | bigint
4941 Argument data types | integer, bigint
4942 Type                | func
4943 Volatility          | immutable
4944 Parallel            | safe
4945 Owner               | postgres
4946 Security            | invoker
4947 Leakproof?          | no
4948 Access privileges   |
4949 Language            | internal
4950 Internal name       | int48pl
4951 Description         | implementation of + operator
4952 .fi
4953 .if n \{\
4954 .RE
4955 .\}
4956 .PP
4957 When suitable, query results can be shown in a crosstab representation with the
4958 \fB\ecrosstabview\fR
4959 command:
4960 .sp
4961 .if n \{\
4962 .RS 4
4963 .\}
4964 .nf
4965 testdb=> \fBSELECT first, second, first > 2 AS gt2 FROM my_table;\fR
4966  first | second | gt2
4967 \-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-+\-\-\-\-\-
4968      1 | one    | f
4969      2 | two    | f
4970      3 | three  | t
4971      4 | four   | t
4972 (4 rows)
4973
4974 testdb=> \fB\ecrosstabview first second\fR
4975  first | one | two | three | four
4976 \-\-\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-+\-\-\-\-\-\-\-+\-\-\-\-\-\-
4977      1 | f   |     |       |
4978      2 |     | f   |       |
4979      3 |     |     | t     |
4980      4 |     |     |       | t
4981 (4 rows)
4982 .fi
4983 .if n \{\
4984 .RE
4985 .\}
4986 .sp
4987 This second example shows a multiplication table with rows sorted in reverse numerical order and columns with an independent, ascending numerical order\&.
4988 .sp
4989 .if n \{\
4990 .RS 4
4991 .\}
4992 .nf
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
5003 (4 rows)
5004 .fi
5005 .if n \{\
5006 .RE
5007 .\}
5008