1999-07-22 17:09:15 +02:00
|
|
|
<!--
|
2010-09-20 22:08:53 +02:00
|
|
|
doc/src/sgml/ref/psql-ref.sgml
|
2001-12-08 04:24:40 +01:00
|
|
|
PostgreSQL documentation
|
1999-07-22 17:09:15 +02:00
|
|
|
-->
|
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refentry id="app-psql">
|
2014-02-24 03:25:35 +01:00
|
|
|
<indexterm zone="app-psql">
|
|
|
|
<primary>psql</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<refmeta>
|
2010-04-03 09:23:02 +02:00
|
|
|
<refentrytitle><application>psql</application></refentrytitle>
|
2000-12-26 00:15:27 +01:00
|
|
|
<manvolnum>1</manvolnum>
|
1999-11-04 23:07:57 +01:00
|
|
|
<refmiscinfo>Application</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
2000-12-26 00:15:27 +01:00
|
|
|
<refname><application>psql</application></refname>
|
1999-11-04 23:07:57 +01:00
|
|
|
<refpurpose>
|
2001-09-03 14:57:50 +02:00
|
|
|
<productname>PostgreSQL</productname> interactive terminal
|
1999-11-04 23:07:57 +01:00
|
|
|
</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsynopsisdiv>
|
|
|
|
<cmdsynopsis>
|
|
|
|
<command>psql</command>
|
2003-03-24 15:32:51 +01:00
|
|
|
<arg rep="repeat"><replaceable class="parameter">option</replaceable></arg>
|
2012-05-03 21:50:04 +02:00
|
|
|
<arg choice="opt"><replaceable class="parameter">dbname</replaceable>
|
|
|
|
<arg choice="opt"><replaceable class="parameter">username</replaceable></arg></arg>
|
2002-07-28 17:22:21 +02:00
|
|
|
</cmdsynopsis>
|
|
|
|
</refsynopsisdiv>
|
1999-06-14 09:37:05 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
<application>psql</application> is a terminal-based front-end to
|
|
|
|
<productname>PostgreSQL</productname>. It enables you to type in
|
|
|
|
queries interactively, issue them to
|
|
|
|
<productname>PostgreSQL</productname>, and see the query results.
|
2015-12-08 20:04:08 +01:00
|
|
|
Alternatively, input can be from a file or from command line
|
2015-12-13 20:52:07 +01:00
|
|
|
arguments. In addition, <application>psql</application> provides a
|
|
|
|
number of meta-commands and various shell-like features to
|
|
|
|
facilitate writing scripts and automating a wide variety of tasks.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect1>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refsect1 id="r1-app-psql-3">
|
2002-07-28 17:22:21 +02:00
|
|
|
<title>Options</title>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<variablelist>
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-echo-all">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-a</option></term>
|
|
|
|
<term><option>--echo-all</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-02-01 00:35:13 +01:00
|
|
|
Print all nonempty input lines to standard output as they are read.
|
|
|
|
(This does not apply to lines read interactively.) This is
|
2002-09-21 20:32:54 +02:00
|
|
|
equivalent to setting the variable <varname>ECHO</varname> to
|
2002-07-28 17:22:21 +02:00
|
|
|
<literal>all</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-no-align">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-A</option></term>
|
|
|
|
<term><option>--no-align</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Switches to unaligned output mode. (The default output mode is
|
2018-11-26 21:18:55 +01:00
|
|
|
<literal>aligned</literal>.) This is equivalent to
|
|
|
|
<command>\pset format unaligned</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-echo-errors">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-b</option></term>
|
|
|
|
<term><option>--echo-errors</option></term>
|
2014-07-10 07:27:54 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Print failed SQL commands to standard error output. This is
|
|
|
|
equivalent to setting the variable <varname>ECHO</varname> to
|
|
|
|
<literal>errors</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-command">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-c <replaceable class="parameter">command</replaceable></option></term>
|
|
|
|
<term><option>--command=<replaceable class="parameter">command</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-12-13 20:52:07 +01:00
|
|
|
Specifies that <application>psql</application> is to execute the given
|
|
|
|
command string, <replaceable class="parameter">command</replaceable>.
|
|
|
|
This option can be repeated and combined in any order with
|
|
|
|
the <option>-f</option> option. When either <option>-c</option>
|
|
|
|
or <option>-f</option> is specified, <application>psql</application>
|
|
|
|
does not read commands from standard input; instead it terminates
|
|
|
|
after processing all the <option>-c</option> and <option>-f</option>
|
|
|
|
options in sequence.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2014-02-14 18:54:39 +01:00
|
|
|
<para>
|
2015-12-13 20:52:07 +01:00
|
|
|
<replaceable class="parameter">command</replaceable> must be either
|
|
|
|
a command string that is completely parsable by the server (i.e.,
|
|
|
|
it contains no <application>psql</application>-specific features),
|
|
|
|
or a single backslash command. Thus you cannot mix
|
|
|
|
<acronym>SQL</acronym> and <application>psql</application>
|
|
|
|
meta-commands within a <option>-c</option> option. To achieve that,
|
|
|
|
you could use repeated <option>-c</option> options or pipe the string
|
|
|
|
into <application>psql</application>, for example:
|
|
|
|
<programlisting>
|
|
|
|
psql -c '\x' -c 'SELECT * FROM foo;'
|
|
|
|
</programlisting>
|
|
|
|
or
|
|
|
|
<programlisting>
|
|
|
|
echo '\x \\ SELECT * FROM foo;' | psql
|
|
|
|
</programlisting>
|
2017-10-09 03:44:17 +02:00
|
|
|
(<literal>\\</literal> is the separator meta-command.)
|
2003-03-24 19:33:52 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2015-12-13 20:52:07 +01:00
|
|
|
Each <acronym>SQL</acronym> command string passed
|
2017-09-07 20:04:41 +02:00
|
|
|
to <option>-c</option> is sent to the server as a single request.
|
2015-12-13 20:52:07 +01:00
|
|
|
Because of this, the server executes it as a single transaction even
|
|
|
|
if the string contains multiple <acronym>SQL</acronym> commands,
|
2017-10-09 03:44:17 +02:00
|
|
|
unless there are explicit <command>BEGIN</command>/<command>COMMIT</command>
|
2015-12-13 20:52:07 +01:00
|
|
|
commands included in the string to divide it into multiple
|
2017-11-23 15:39:47 +01:00
|
|
|
transactions. (See <xref linkend="protocol-flow-multi-statement"/>
|
2017-09-07 20:04:41 +02:00
|
|
|
for more details about how the server handles multi-query strings.)
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2014-02-14 18:54:39 +01:00
|
|
|
<para>
|
2022-04-11 21:11:46 +02:00
|
|
|
If having several commands executed in one transaction is not desired,
|
2022-04-04 14:57:17 +02:00
|
|
|
use repeated <option>-c</option> commands or feed multiple commands to
|
|
|
|
<application>psql</application>'s standard input,
|
2015-12-08 20:04:08 +01:00
|
|
|
either using <application>echo</application> as illustrated above, or
|
|
|
|
via a shell here-document, for example:
|
2014-02-14 18:54:39 +01:00
|
|
|
<programlisting>
|
|
|
|
psql <<EOF
|
|
|
|
\x
|
|
|
|
SELECT * FROM foo;
|
|
|
|
EOF
|
2020-06-07 14:54:28 +02:00
|
|
|
</programlisting></para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-csv">
|
2018-11-26 21:18:55 +01:00
|
|
|
<term><option>--csv</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Switches to <acronym>CSV</acronym> (Comma-Separated Values) output
|
|
|
|
mode. This is equivalent to <command>\pset format csv</command>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-dbname">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-d <replaceable class="parameter">dbname</replaceable></option></term>
|
|
|
|
<term><option>--dbname=<replaceable class="parameter">dbname</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2007-02-22 00:21:12 +01:00
|
|
|
Specifies the name of the database to connect to. This is
|
|
|
|
equivalent to specifying <replaceable
|
|
|
|
class="parameter">dbname</replaceable> as the first non-option
|
2020-10-03 04:19:31 +02:00
|
|
|
argument on the command line. The <replaceable>dbname</replaceable>
|
|
|
|
can be a <link linkend="libpq-connstring">connection string</link>.
|
|
|
|
If so, connection string parameters will override any conflicting
|
|
|
|
command line options.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-echo-queries">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-e</option></term>
|
|
|
|
<term><option>--echo-queries</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-04 04:58:16 +01:00
|
|
|
Copy all SQL commands sent to the server to standard output as well.
|
|
|
|
This is equivalent
|
2002-09-21 20:32:54 +02:00
|
|
|
to setting the variable <varname>ECHO</varname> to
|
2002-07-28 17:22:21 +02:00
|
|
|
<literal>queries</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-echo-hidden">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-E</option></term>
|
|
|
|
<term><option>--echo-hidden</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Echo the actual queries generated by <command>\d</command> and other backslash
|
2005-01-04 04:58:16 +01:00
|
|
|
commands. You can use this to study <application>psql</application>'s
|
|
|
|
internal operations. This is equivalent to
|
2017-10-09 03:44:17 +02:00
|
|
|
setting the variable <varname>ECHO_HIDDEN</varname> to <literal>on</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-file">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
|
|
|
|
<term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-12-13 20:52:07 +01:00
|
|
|
Read commands from the
|
|
|
|
file <replaceable class="parameter">filename</replaceable>,
|
|
|
|
rather than standard input.
|
|
|
|
This option can be repeated and combined in any order with
|
|
|
|
the <option>-c</option> option. When either <option>-c</option>
|
|
|
|
or <option>-f</option> is specified, <application>psql</application>
|
|
|
|
does not read commands from standard input; instead it terminates
|
|
|
|
after processing all the <option>-c</option> and <option>-f</option>
|
|
|
|
options in sequence.
|
|
|
|
Except for that, this option is largely equivalent to the
|
|
|
|
meta-command <command>\i</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
If <replaceable>filename</replaceable> is <literal>-</literal>
|
2015-12-13 20:52:07 +01:00
|
|
|
(hyphen), then standard input is read until an EOF indication
|
2017-10-09 03:44:17 +02:00
|
|
|
or <command>\q</command> meta-command. This can be used to intersperse
|
2015-12-13 20:52:07 +01:00
|
|
|
interactive input with input from files. Note however that Readline
|
|
|
|
is not used in this case (much as if <option>-n</option> had been
|
|
|
|
specified).
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
Using this option is subtly different from writing <literal>psql
|
|
|
|
< <replaceable
|
|
|
|
class="parameter">filename</replaceable></literal>. In general,
|
|
|
|
both will do what you expect, but using <literal>-f</literal>
|
|
|
|
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's input redirection is (in theory) guaranteed to yield
|
2010-02-19 04:50:03 +01:00
|
|
|
exactly the same output you would have received had you entered
|
2002-07-28 17:22:21 +02:00
|
|
|
everything by hand.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-05 16:44:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-field-separator">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-F <replaceable class="parameter">separator</replaceable></option></term>
|
|
|
|
<term><option>--field-separator=<replaceable class="parameter">separator</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Use <replaceable class="parameter">separator</replaceable> as the
|
2005-03-14 07:19:01 +01:00
|
|
|
field separator for unaligned output. This is equivalent to
|
|
|
|
<command>\pset fieldsep</command> or <command>\f</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-05 01:57:39 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-field-host">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-h <replaceable class="parameter">hostname</replaceable></option></term>
|
|
|
|
<term><option>--host=<replaceable class="parameter">hostname</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies the host name of the machine on which the
|
2003-03-24 15:32:51 +01:00
|
|
|
server is running. If the value begins
|
2002-09-21 20:32:54 +02:00
|
|
|
with a slash, it is used as the directory for the Unix-domain
|
2002-07-28 17:22:21 +02:00
|
|
|
socket.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-html">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-H</option></term>
|
|
|
|
<term><option>--html</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2018-11-26 21:18:55 +01:00
|
|
|
Switches to <acronym>HTML</acronym> output mode. This is
|
|
|
|
equivalent to <command>\pset format html</command> or the
|
2002-07-28 17:22:21 +02:00
|
|
|
<command>\H</command> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-list">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-l</option></term>
|
|
|
|
<term><option>--list</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-04 04:58:16 +01:00
|
|
|
List all available databases, then exit. Other non-connection
|
2018-02-03 16:19:57 +01:00
|
|
|
options are ignored. This is similar to the meta-command
|
2002-07-28 17:22:21 +02:00
|
|
|
<command>\list</command>.
|
|
|
|
</para>
|
2018-02-03 16:19:57 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
When this option is used, <application>psql</application> will connect
|
|
|
|
to the database <literal>postgres</literal>, unless a different database
|
|
|
|
is named on the command line (option <option>-d</option> or non-option
|
|
|
|
argument, possibly via a service entry, but not via an environment
|
|
|
|
variable).
|
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-log-file">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-L <replaceable class="parameter">filename</replaceable></option></term>
|
|
|
|
<term><option>--log-file=<replaceable class="parameter">filename</replaceable></option></term>
|
2005-06-14 04:57:45 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-11-01 22:09:51 +01:00
|
|
|
Write all query output into file <replaceable
|
|
|
|
class="parameter">filename</replaceable>, in addition to the
|
|
|
|
normal output destination.
|
2005-06-14 04:57:45 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-no-readline">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-n</option></term>
|
|
|
|
<term><option>--no-readline</option></term>
|
2009-08-10 04:39:04 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
Do not use <application>Readline</application> for line editing and
|
|
|
|
do not use the command history (see
|
|
|
|
<xref linkend="app-psql-readline"/> below).
|
2009-08-10 04:39:04 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-output">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-o <replaceable class="parameter">filename</replaceable></option></term>
|
|
|
|
<term><option>--output=<replaceable class="parameter">filename</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Put all query output into file <replaceable
|
|
|
|
class="parameter">filename</replaceable>. This is equivalent to
|
|
|
|
the command <command>\o</command>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-port">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-p <replaceable class="parameter">port</replaceable></option></term>
|
|
|
|
<term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-12-29 00:17:54 +01:00
|
|
|
Specifies the TCP port or the local Unix-domain
|
2003-03-24 15:32:51 +01:00
|
|
|
socket file extension on which the server is listening for
|
2002-07-28 17:22:21 +02:00
|
|
|
connections. Defaults to the value of the <envar>PGPORT</envar>
|
|
|
|
environment variable or, if not set, to the port specified at
|
|
|
|
compile time, usually 5432.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-pset">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-P <replaceable class="parameter">assignment</replaceable></option></term>
|
|
|
|
<term><option>--pset=<replaceable class="parameter">assignment</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
Specifies printing options, in the style of
|
|
|
|
<command>\pset</command>. Note that here you
|
2002-07-28 17:22:21 +02:00
|
|
|
have to separate name and value with an equal sign instead of a
|
2012-06-07 23:06:20 +02:00
|
|
|
space. For example, to set the output format to <application>LaTeX</application>, you could write
|
2002-07-28 17:22:21 +02:00
|
|
|
<literal>-P format=latex</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-quiet">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-q</option></term>
|
|
|
|
<term><option>--quiet</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies that <application>psql</application> 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 <option>-c</option> option.
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
This is equivalent to setting the variable <varname>QUIET</varname>
|
2017-10-09 03:44:17 +02:00
|
|
|
to <literal>on</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-record-separator">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-R <replaceable class="parameter">separator</replaceable></option></term>
|
|
|
|
<term><option>--record-separator=<replaceable class="parameter">separator</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Use <replaceable class="parameter">separator</replaceable> as the
|
2017-07-05 03:10:08 +02:00
|
|
|
record separator for unaligned output. This is equivalent to
|
|
|
|
<command>\pset recordsep</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-single-step">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-s</option></term>
|
|
|
|
<term><option>--single-step</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Run in single-step mode. That means the user is prompted before
|
2003-03-24 15:32:51 +01:00
|
|
|
each command is sent to the server, with the option to cancel
|
2002-07-28 17:22:21 +02:00
|
|
|
execution as well. Use this to debug scripts.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-single-line">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-S</option></term>
|
|
|
|
<term><option>--single-line</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Runs in single-line mode where a newline terminates an SQL command, as a
|
2002-07-28 17:22:21 +02:00
|
|
|
semicolon does.
|
|
|
|
</para>
|
2001-05-07 21:31:33 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
This mode is provided for those who insist on it, but you are not
|
|
|
|
necessarily encouraged to use it. In particular, if you mix
|
|
|
|
<acronym>SQL</acronym> and meta-commands on a line the order of
|
|
|
|
execution might not always be clear to the inexperienced user.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2001-05-07 21:31:33 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-tuples-only">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-t</option></term>
|
|
|
|
<term><option>--tuples-only</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Turn off printing of column names and result row count footers,
|
2017-07-05 03:10:08 +02:00
|
|
|
etc. This is equivalent to <command>\t</command> or
|
|
|
|
<command>\pset tuples_only</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-table-attr">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-T <replaceable class="parameter">table_options</replaceable></option></term>
|
|
|
|
<term><option>--table-attr=<replaceable class="parameter">table_options</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
Specifies options to be placed within the
|
2002-07-28 17:22:21 +02:00
|
|
|
<acronym>HTML</acronym> <sgmltag>table</sgmltag> tag. See
|
2017-07-05 03:10:08 +02:00
|
|
|
<command>\pset tableattr</command> for details.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-username">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-U <replaceable class="parameter">username</replaceable></option></term>
|
|
|
|
<term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Connect to the database as the user <replaceable
|
2002-07-28 17:22:21 +02:00
|
|
|
class="parameter">username</replaceable> instead of the default.
|
|
|
|
(You must have permission to do so, of course.)
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-variable">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-v <replaceable class="parameter">assignment</replaceable></option></term>
|
|
|
|
<term><option>--set=<replaceable class="parameter">assignment</replaceable></option></term>
|
|
|
|
<term><option>--variable=<replaceable class="parameter">assignment</replaceable></option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Perform a variable assignment, like the <command>\set</command>
|
2011-08-26 19:52:23 +02:00
|
|
|
meta-command. Note that you must separate name and value, if
|
2002-07-28 17:22:21 +02:00
|
|
|
any, by an equal sign on the command line. To unset a variable,
|
2011-08-26 19:52:23 +02:00
|
|
|
leave off the equal sign. To set a variable with an empty value,
|
2002-07-28 17:22:21 +02:00
|
|
|
use the equal sign but leave off the value. These assignments are
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
done during command line processing, so variables that reflect
|
|
|
|
connection state will get overwritten later.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-version">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-V</option></term>
|
|
|
|
<term><option>--version</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-04 04:58:16 +01:00
|
|
|
Print the <application>psql</application> version and exit.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-no-password">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-w</option></term>
|
|
|
|
<term><option>--no-password</option></term>
|
2009-02-26 17:02:39 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Never issue a password prompt. If the server requires password
|
2020-10-03 04:19:31 +02:00
|
|
|
authentication and a password is not available from other sources
|
2009-02-26 17:02:39 +01:00
|
|
|
such as a <filename>.pgpass</filename> 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.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Note that this option will remain set for the entire session,
|
|
|
|
and so it affects uses of the meta-command
|
|
|
|
<command>\connect</command> as well as the initial connection attempt.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-password">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-W</option></term>
|
|
|
|
<term><option>--password</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2007-12-11 20:57:32 +01:00
|
|
|
Force <application>psql</application> to prompt for a
|
2020-10-03 04:19:31 +02:00
|
|
|
password before connecting to a database, even if the password will
|
|
|
|
not be used.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2020-10-03 04:19:31 +02:00
|
|
|
If the server requires password authentication and a password is not
|
|
|
|
available from other sources such as a <filename>.pgpass</filename>
|
|
|
|
file, <application>psql</application> will prompt for a
|
|
|
|
password in any case. However, <application>psql</application>
|
2007-12-11 20:57:32 +01:00
|
|
|
will waste a connection attempt finding out that the server wants a
|
2017-10-09 03:44:17 +02:00
|
|
|
password. In some cases it is worth typing <option>-W</option> to avoid
|
2007-12-11 20:57:32 +01:00
|
|
|
the extra connection attempt.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2005-02-11 05:19:05 +01:00
|
|
|
|
|
|
|
<para>
|
2007-12-11 20:57:32 +01:00
|
|
|
Note that this option will remain set for the entire session,
|
|
|
|
and so it affects uses of the meta-command
|
|
|
|
<command>\connect</command> as well as the initial connection attempt.
|
2005-02-11 05:19:05 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-expanded">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-x</option></term>
|
|
|
|
<term><option>--expanded</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-07-05 03:10:08 +02:00
|
|
|
Turn on the expanded table formatting mode. This is equivalent to
|
|
|
|
<command>\x</command> or <command>\pset expanded</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-no-psqlrc">
|
2024-04-09 23:39:38 +02:00
|
|
|
<term><option>-X</option></term>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>--no-psqlrc</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-06 19:29:11 +01:00
|
|
|
Do not read the start-up file (neither the system-wide
|
|
|
|
<filename>psqlrc</filename> file nor the user's
|
|
|
|
<filename>~/.psqlrc</filename> file).
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-field-separator-zero">
|
2012-02-09 19:15:48 +01:00
|
|
|
<term><option>-z</option></term>
|
|
|
|
<term><option>--field-separator-zero</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-07-05 03:10:08 +02:00
|
|
|
Set the field separator for unaligned output to a zero byte. This is
|
2018-06-29 21:26:41 +02:00
|
|
|
equivalent to <command>\pset fieldsep_zero</command>.
|
2012-02-09 19:15:48 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-record-separator-zero">
|
2012-02-09 19:15:48 +01:00
|
|
|
<term><option>-0</option></term>
|
|
|
|
<term><option>--record-separator-zero</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Set the record separator for unaligned output to a zero byte. This is
|
|
|
|
useful for interfacing, for example, with <literal>xargs -0</literal>.
|
2017-07-05 03:10:08 +02:00
|
|
|
This is equivalent to <command>\pset recordsep_zero</command>.
|
2012-02-09 19:15:48 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-single-transaction">
|
2006-02-12 05:04:32 +01:00
|
|
|
<term><option>-1</option></term>
|
|
|
|
<term><option>--single-transaction</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-12-13 20:52:07 +01:00
|
|
|
This option can only be used in combination with one or more
|
|
|
|
<option>-c</option> and/or <option>-f</option> options. It causes
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>psql</application> to issue a <command>BEGIN</command> command
|
|
|
|
before the first such option and a <command>COMMIT</command> command after
|
2015-12-13 20:52:07 +01:00
|
|
|
the last one, thereby wrapping all the commands into a single
|
Tweak behavior of psql --single-transaction depending on ON_ERROR_STOP
This commit, in completion of 157f873, forces a ROLLBACK for
--single-transaction only when ON_ERROR_STOP is used when one of the
steps defined by -f/-c fails. Hence, COMMIT is always used when
ON_ERROR_STOP is not set, ignoring the status code of the last action
taken in the set of switches specified by -c/-f (previously ROLLBACK
would have been issued even without ON_ERROR_STOP if the last step
failed, while COMMIT was issued if a step in-between failed as long as
the last step succeeded, leading to more inconsistency).
While on it, this adds much more test coverage in this area when not
using ON_ERROR_STOP with multiple switch patterns involving -c and -f
for query files, single queries and slash commands.
The behavior of ON_ERROR_STOP is arguably a bug, but there was no much
support for a backpatch to force a ROLLBACK on a step failure, so this
change is done only on HEAD for now.
Per discussion with Tom Lane and Kyotaro Horiguchi.
Discussion: https://postgr.es/m/Yqbc8bAdwnP02na4@paquier.xyz
2022-06-15 04:24:52 +02:00
|
|
|
transaction. If any of the commands fails and the variable
|
|
|
|
<varname>ON_ERROR_STOP</varname> was set, a
|
2022-06-06 04:05:59 +02:00
|
|
|
<command>ROLLBACK</command> command is sent instead. This ensures that
|
|
|
|
either all the commands complete successfully, or no changes are
|
|
|
|
applied.
|
2006-10-31 02:52:31 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2015-12-08 20:04:08 +01:00
|
|
|
If the commands themselves
|
2017-10-09 03:44:17 +02:00
|
|
|
contain <command>BEGIN</command>, <command>COMMIT</command>,
|
|
|
|
or <command>ROLLBACK</command>, this option will not have the desired
|
2015-12-08 20:04:08 +01:00
|
|
|
effects. Also, if an individual command cannot be executed inside a
|
|
|
|
transaction block, specifying this option will cause the whole
|
|
|
|
transaction to fail.
|
2006-02-12 05:04:32 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-option-help">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-?</option></term>
|
|
|
|
<term><option>--help[=<replaceable class="parameter">topic</replaceable>]</option></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
Add new psql help topics, accessible to both --help and \?.
Add --help=<topic> for the commandline, and \? <topic> as a backslash
command, to show more help than the invocations without parameters
do. "commands", "variables" and "options" currently exist as help
topics describing, respectively, backslash commands, psql variables,
and commandline switches. Without parameters the help commands show
their previous topic.
Some further wordsmithing or extending of the added help content might
be needed; but there seems little benefit delaying the overall feature
further.
Author: Pavel Stehule, editorialized by many
Reviewed-By: Andres Freund, Petr Jelinek, Fujii Masao, MauMau, Abhijit
Menon-Sen and Erik Rijkers.
Discussion: CAFj8pRDVGuC-nXBfe2CK8vpyzd2Dsr9GVpbrATAnZO=2YQ0s2Q@mail.gmail.com,
CAFj8pRA54AbTv2RXDTRxiAd8hy8wxmoVLqhJDRCwEnhdd7OUkw@mail.gmail.com
2014-09-09 22:19:14 +02:00
|
|
|
Show help about <application>psql</application> and exit. The optional
|
2017-10-09 03:44:17 +02:00
|
|
|
<replaceable class="parameter">topic</replaceable> parameter (defaulting
|
2015-09-11 03:22:21 +02:00
|
|
|
to <literal>options</literal>) selects which part of <application>psql</application> is
|
2017-10-09 03:44:17 +02:00
|
|
|
explained: <literal>commands</literal> describes <application>psql</application>'s
|
|
|
|
backslash commands; <literal>options</literal> describes the command-line
|
|
|
|
options that can be passed to <application>psql</application>;
|
|
|
|
and <literal>variables</literal> shows help about <application>psql</application> configuration
|
Add new psql help topics, accessible to both --help and \?.
Add --help=<topic> for the commandline, and \? <topic> as a backslash
command, to show more help than the invocations without parameters
do. "commands", "variables" and "options" currently exist as help
topics describing, respectively, backslash commands, psql variables,
and commandline switches. Without parameters the help commands show
their previous topic.
Some further wordsmithing or extending of the added help content might
be needed; but there seems little benefit delaying the overall feature
further.
Author: Pavel Stehule, editorialized by many
Reviewed-By: Andres Freund, Petr Jelinek, Fujii Masao, MauMau, Abhijit
Menon-Sen and Erik Rijkers.
Discussion: CAFj8pRDVGuC-nXBfe2CK8vpyzd2Dsr9GVpbrATAnZO=2YQ0s2Q@mail.gmail.com,
CAFj8pRA54AbTv2RXDTRxiAd8hy8wxmoVLqhJDRCwEnhdd7OUkw@mail.gmail.com
2014-09-09 22:19:14 +02:00
|
|
|
variables.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2010-02-19 15:36:45 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</variablelist>
|
|
|
|
</refsect1>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Exit Status</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
<application>psql</application> returns 0 to the shell if it
|
2020-09-01 00:33:37 +02:00
|
|
|
finished normally, 1 if a fatal error of its own occurs (e.g., out of memory,
|
2010-02-19 04:50:03 +01:00
|
|
|
file not found), 2 if the connection to the server went bad
|
2003-03-24 15:32:51 +01:00
|
|
|
and the session was not interactive, and 3 if an error occurred in a
|
2002-09-21 20:32:54 +02:00
|
|
|
script and the variable <varname>ON_ERROR_STOP</varname> was set.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Usage</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refsect2 id="r2-app-psql-connecting">
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>Connecting to a Database</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
<application>psql</application> is a regular
|
|
|
|
<productname>PostgreSQL</productname> client application. In order
|
|
|
|
to connect to a database you need to know the name of your target
|
2022-11-24 09:04:50 +01:00
|
|
|
database, the host name and port number of the server, and what
|
|
|
|
database user name you want to connect as. <application>psql</application>
|
|
|
|
can be told about those parameters via command line options, namely
|
2002-07-28 17:22:21 +02:00
|
|
|
<option>-d</option>, <option>-h</option>, <option>-p</option>, and
|
|
|
|
<option>-U</option> respectively. If an argument is found that does
|
|
|
|
not belong to any option it will be interpreted as the database name
|
2022-11-24 09:04:50 +01:00
|
|
|
(or the database user name, if the database name is already given). Not all
|
2010-02-19 04:50:03 +01:00
|
|
|
of these options are required; there are useful defaults. If you omit the host
|
2017-10-09 03:44:17 +02:00
|
|
|
name, <application>psql</application> will connect via a Unix-domain socket
|
|
|
|
to a server on the local host, or via TCP/IP to <literal>localhost</literal> on
|
Remove HAVE_UNIX_SOCKETS.
Since HAVE_UNIX_SOCKETS is now defined unconditionally, remove the macro
and drop a small amount of dead code.
The last known systems not to have them (as far as I know at least) were
QNX, which we de-supported years ago, and Windows, which now has them.
If a new OS ever shows up with the POSIX sockets API but without working
AF_UNIX, it'll presumably still be able to compile the code, and fail at
runtime with an unsupported address family error. We might want to
consider adding a HINT that you should turn off the option to use it if
your network stack doesn't support it at that point, but it doesn't seem
worth making the relevant code conditional at compile time.
Also adjust a couple of places in the docs and comments that referred to
builds without Unix-domain sockets, since there aren't any. Windows
still gets a special mention in those places, though, because we don't
try to use them by default there yet.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/CA%2BhUKG%2BL_3brvh%3D8e0BW_VfX9h7MtwgN%3DnFHP5o7X2oZucY9dg%40mail.gmail.com
2022-08-13 22:46:53 +02:00
|
|
|
Windows. The default port number is
|
2004-12-29 00:17:54 +01:00
|
|
|
determined at compile time.
|
2002-07-28 17:22:21 +02:00
|
|
|
Since the database server uses the same default, you will not have
|
2022-11-24 09:04:50 +01:00
|
|
|
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.
|
2014-12-29 20:20:54 +01:00
|
|
|
Note that you cannot
|
2022-11-24 09:04:50 +01:00
|
|
|
just connect to any database under any database user name. Your database
|
2004-12-29 00:17:54 +01:00
|
|
|
administrator should have informed you about your access rights.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When the defaults aren't quite right, you can save yourself
|
|
|
|
some typing by setting the environment variables
|
2002-07-28 17:22:21 +02:00
|
|
|
<envar>PGDATABASE</envar>, <envar>PGHOST</envar>,
|
2004-12-29 00:17:54 +01:00
|
|
|
<envar>PGPORT</envar> and/or <envar>PGUSER</envar> to appropriate
|
2005-02-11 05:19:05 +01:00
|
|
|
values. (For additional environment variables, see <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="libpq-envars"/>.) It is also convenient to have a
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>~/.pgpass</filename> file to avoid regularly having to type in
|
2017-11-23 15:39:47 +01:00
|
|
|
passwords. See <xref linkend="libpq-pgpass"/> for more information.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2007-02-22 00:21:12 +01:00
|
|
|
<para>
|
|
|
|
An alternative way to specify connection parameters is in a
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
<parameter>conninfo</parameter> string or
|
|
|
|
a <acronym>URI</acronym>, which is used instead of a database
|
|
|
|
name. This mechanism give you very wide control over the
|
2007-02-22 00:21:12 +01:00
|
|
|
connection. For example:
|
2006-12-19 02:53:36 +01:00
|
|
|
<programlisting>
|
|
|
|
$ <userinput>psql "service=myservice sslmode=require"</userinput>
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
$ <userinput>psql postgresql://dbmaster:5433/mydb?sslmode=require</userinput>
|
2006-12-19 02:53:36 +01:00
|
|
|
</programlisting>
|
2013-02-21 11:26:23 +01:00
|
|
|
This way you can also use <acronym>LDAP</acronym> for connection
|
2017-11-23 15:39:47 +01:00
|
|
|
parameter lookup as described in <xref linkend="libpq-ldap"/>.
|
|
|
|
See <xref linkend="libpq-paramkeywords"/> for more information on all the
|
2007-02-22 00:21:12 +01:00
|
|
|
available connection options.
|
|
|
|
</para>
|
2006-12-19 02:53:36 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
If the connection could not be made for any reason (e.g., insufficient
|
2003-03-24 15:32:51 +01:00
|
|
|
privileges, server is not running on the targeted host, etc.),
|
2002-07-28 17:22:21 +02:00
|
|
|
<application>psql</application> will return an error and terminate.
|
|
|
|
</para>
|
2011-02-19 07:54:58 +01:00
|
|
|
|
|
|
|
<para>
|
2014-04-17 01:53:42 +02:00
|
|
|
If both standard input and standard output are a
|
2011-02-19 07:54:58 +01:00
|
|
|
terminal, then <application>psql</application> sets the client
|
|
|
|
encoding to <quote>auto</quote>, which will detect the
|
|
|
|
appropriate client encoding from the locale settings
|
|
|
|
(<envar>LC_CTYPE</envar> environment variable on Unix systems).
|
|
|
|
If this doesn't work out as expected, the client encoding can be
|
|
|
|
overridden using the environment
|
|
|
|
variable <envar>PGCLIENTENCODING</envar>.
|
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect2>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refsect2 id="r2-app-psql-4">
|
2003-03-24 15:32:51 +01:00
|
|
|
<title>Entering SQL Commands</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
In normal operation, <application>psql</application> provides a
|
|
|
|
prompt with the name of the database to which
|
|
|
|
<application>psql</application> is currently connected, followed by
|
2007-02-01 01:28:19 +01:00
|
|
|
the string <literal>=></literal>. For example:
|
2002-07-28 17:22:21 +02:00
|
|
|
<programlisting>
|
|
|
|
$ <userinput>psql testdb</userinput>
|
2008-05-16 19:17:00 +02:00
|
|
|
psql (&version;)
|
|
|
|
Type "help" for help.
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=>
|
2002-07-28 17:22:21 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
2002-03-19 03:32:21 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
Update reference documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 00:26:05 +01:00
|
|
|
At the prompt, the user can type in <acronym>SQL</acronym> commands.
|
2003-03-24 15:32:51 +01:00
|
|
|
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
|
2005-01-04 04:58:16 +01:00
|
|
|
clarity. If the command was sent and executed without error, the results
|
|
|
|
of the command are displayed on the screen.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2002-03-19 03:32:21 +01:00
|
|
|
|
Document security implications of search_path and the public schema.
The ability to create like-named objects in different schemas opens up
the potential for users to change the behavior of other users' queries,
maliciously or accidentally. When you connect to a PostgreSQL server,
you should remove from your search_path any schema for which a user
other than yourself or superusers holds the CREATE privilege. If you do
not, other users holding CREATE privilege can redefine the behavior of
your commands, causing them to perform arbitrary SQL statements under
your identity. "SET search_path = ..." and "SELECT
pg_catalog.set_config(...)" are not vulnerable to such hijacking, so one
can use either as the first command of a session. As special
exceptions, the following client applications behave as documented
regardless of search_path settings and schema privileges: clusterdb
createdb createlang createuser dropdb droplang dropuser ecpg (not
programs it generates) initdb oid2name pg_archivecleanup pg_basebackup
pg_config pg_controldata pg_ctl pg_dump pg_dumpall pg_isready
pg_receivewal pg_recvlogical pg_resetwal pg_restore pg_rewind pg_standby
pg_test_fsync pg_test_timing pg_upgrade pg_waldump reindexdb vacuumdb
vacuumlo. Not included are core client programs that run user-specified
SQL commands, namely psql and pgbench. PostgreSQL encourages non-core
client applications to do likewise.
Document this in the context of libpq connections, psql connections,
dblink connections, ECPG connections, extension packaging, and schema
usage patterns. The principal defense for applications is "SELECT
pg_catalog.set_config('search_path', '', false)", and the principal
defense for databases is "REVOKE CREATE ON SCHEMA public FROM PUBLIC".
Either one is sufficient to prevent attack. After a REVOKE, consider
auditing the public schema for objects named like pg_catalog objects.
Authors of SECURITY DEFINER functions use some of the same defenses, and
the CREATE FUNCTION reference page already covered them thoroughly.
This is a good opportunity to audit SECURITY DEFINER functions for
robust security practice.
Back-patch to 9.3 (all supported versions).
Reviewed by Michael Paquier and Jonathan S. Katz. Reported by Arseniy
Sharoglazov.
Security: CVE-2018-1058
2018-02-26 16:39:44 +01:00
|
|
|
<para>
|
|
|
|
If untrusted users have access to a database that has not adopted a
|
|
|
|
<link linkend="ddl-schemas-patterns">secure schema usage pattern</link>,
|
|
|
|
begin your session by removing publicly-writable schemas
|
|
|
|
from <varname>search_path</varname>. One can
|
|
|
|
add <literal>options=-csearch_path=</literal> to the connection string or
|
|
|
|
issue <literal>SELECT pg_catalog.set_config('search_path', '',
|
|
|
|
false)</literal> before other SQL commands. This consideration is not
|
|
|
|
specific to <application>psql</application>; it applies to every interface
|
|
|
|
for executing arbitrary SQL commands.
|
|
|
|
</para>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Whenever a command is executed, <application>psql</application> also polls
|
2002-07-28 17:22:21 +02:00
|
|
|
for asynchronous notification events generated by
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-listen"><command>LISTEN</command></link> and
|
|
|
|
<link linkend="sql-notify"><command>NOTIFY</command></link>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2014-04-10 23:16:22 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
While C-style block comments are passed to the server for
|
|
|
|
processing and removal, SQL-standard comments are removed by
|
|
|
|
<application>psql</application>.
|
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect2>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refsect2 id="app-psql-meta-commands">
|
2002-07-28 17:22:21 +02:00
|
|
|
<title>Meta-Commands</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
Anything you enter in <application>psql</application> that begins
|
|
|
|
with an unquoted backslash is a <application>psql</application>
|
|
|
|
meta-command that is processed by <application>psql</application>
|
2010-02-19 04:50:03 +01:00
|
|
|
itself. These commands make
|
2005-01-04 04:58:16 +01:00
|
|
|
<application>psql</application> more useful for administration or
|
2009-12-25 00:36:39 +01:00
|
|
|
scripting. Meta-commands are often called slash or backslash commands.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
The format of a <application>psql</application> command is the backslash,
|
2002-07-28 17:22:21 +02:00
|
|
|
followed immediately by a command verb, then any arguments. The arguments
|
2004-06-18 08:14:31 +02:00
|
|
|
are separated from the command verb and each other by any number of
|
2002-07-28 17:22:21 +02:00
|
|
|
whitespace characters.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2011-08-26 19:52:23 +02:00
|
|
|
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
|
2002-07-28 17:22:21 +02:00
|
|
|
furthermore subject to C-like substitutions for
|
2005-06-02 03:23:48 +02:00
|
|
|
<literal>\n</literal> (new line), <literal>\t</literal> (tab),
|
2011-08-26 19:52:23 +02:00
|
|
|
<literal>\b</literal> (backspace), <literal>\r</literal> (carriage return),
|
|
|
|
<literal>\f</literal> (form feed),
|
2005-11-01 22:09:51 +01:00
|
|
|
<literal>\</literal><replaceable>digits</replaceable> (octal), and
|
2005-06-02 03:23:48 +02:00
|
|
|
<literal>\x</literal><replaceable>digits</replaceable> (hexadecimal).
|
2011-08-26 19:52:23 +02:00
|
|
|
A backslash preceding any other character within single-quoted text
|
|
|
|
quotes that single character, whatever it is.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2011-08-26 19:52:23 +02:00
|
|
|
If an unquoted colon (<literal>:</literal>) followed by a
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>psql</application> variable name appears within an argument, it is
|
2011-08-26 19:52:23 +02:00
|
|
|
replaced by the variable's value, as described in <xref
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
linkend="app-psql-interpolation"/> below.
|
2017-10-09 03:44:17 +02:00
|
|
|
The forms <literal>:'<replaceable>variable_name</replaceable>'</literal> and
|
|
|
|
<literal>:"<replaceable>variable_name</replaceable>"</literal> described there
|
Allow psql variable substitution to occur in backtick command strings.
Previously, text between backquotes in a psql metacommand's arguments
was always passed to the shell literally. That considerably hobbles
the usefulness of the feature for scripting, so we'd foreseen for a long
time that we'd someday want to allow substitution of psql variables into
the shell command. IMO the addition of \if metacommands has brought us to
that point, since \if can greatly benefit from some sort of client-side
expression evaluation capability, and psql itself is not going to grow any
such thing in time for v10. Hence, this patch. It allows :VARIABLE to be
replaced by the exact contents of the named variable, while :'VARIABLE'
is replaced by the variable's contents suitably quoted to become a single
shell-command argument. (The quoting rules for that are different from
those for SQL literals, so this is a bit of an abuse of the :'VARIABLE'
notation, but I doubt anyone will be confused.)
As with other situations in psql, no substitution occurs if the word
following a colon is not a known variable name. That limits the risk of
compatibility problems for existing psql scripts; but the risk isn't zero,
so this needs to be called out in the v10 release notes.
Discussion: https://postgr.es/m/9561.1490895211@sss.pgh.pa.us
2017-04-02 03:44:54 +02:00
|
|
|
work as well.
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>:{?<replaceable>variable_name</replaceable>}</literal> syntax allows
|
2017-09-22 01:02:23 +02:00
|
|
|
testing whether a variable is defined. It is substituted by
|
|
|
|
TRUE or FALSE.
|
|
|
|
Escaping the colon with a backslash protects it from substitution.
|
Allow psql variable substitution to occur in backtick command strings.
Previously, text between backquotes in a psql metacommand's arguments
was always passed to the shell literally. That considerably hobbles
the usefulness of the feature for scripting, so we'd foreseen for a long
time that we'd someday want to allow substitution of psql variables into
the shell command. IMO the addition of \if metacommands has brought us to
that point, since \if can greatly benefit from some sort of client-side
expression evaluation capability, and psql itself is not going to grow any
such thing in time for v10. Hence, this patch. It allows :VARIABLE to be
replaced by the exact contents of the named variable, while :'VARIABLE'
is replaced by the variable's contents suitably quoted to become a single
shell-command argument. (The quoting rules for that are different from
those for SQL literals, so this is a bit of an abuse of the :'VARIABLE'
notation, but I doubt anyone will be confused.)
As with other situations in psql, no substitution occurs if the word
following a colon is not a known variable name. That limits the risk of
compatibility problems for existing psql scripts; but the risk isn't zero,
so this needs to be called out in the v10 release notes.
Discussion: https://postgr.es/m/9561.1490895211@sss.pgh.pa.us
2017-04-02 03:44:54 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Within an argument, text that is enclosed in backquotes
|
|
|
|
(<literal>`</literal>) 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
|
2017-10-09 03:44:17 +02:00
|
|
|
of <literal>:<replaceable>variable_name</replaceable></literal> where
|
|
|
|
<replaceable>variable_name</replaceable> is a <application>psql</application> variable name
|
Allow psql variable substitution to occur in backtick command strings.
Previously, text between backquotes in a psql metacommand's arguments
was always passed to the shell literally. That considerably hobbles
the usefulness of the feature for scripting, so we'd foreseen for a long
time that we'd someday want to allow substitution of psql variables into
the shell command. IMO the addition of \if metacommands has brought us to
that point, since \if can greatly benefit from some sort of client-side
expression evaluation capability, and psql itself is not going to grow any
such thing in time for v10. Hence, this patch. It allows :VARIABLE to be
replaced by the exact contents of the named variable, while :'VARIABLE'
is replaced by the variable's contents suitably quoted to become a single
shell-command argument. (The quoting rules for that are different from
those for SQL literals, so this is a bit of an abuse of the :'VARIABLE'
notation, but I doubt anyone will be confused.)
As with other situations in psql, no substitution occurs if the word
following a colon is not a known variable name. That limits the risk of
compatibility problems for existing psql scripts; but the risk isn't zero,
so this needs to be called out in the v10 release notes.
Discussion: https://postgr.es/m/9561.1490895211@sss.pgh.pa.us
2017-04-02 03:44:54 +02:00
|
|
|
are replaced by the variable's value. Also, appearances of
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>:'<replaceable>variable_name</replaceable>'</literal> are replaced by the
|
Allow psql variable substitution to occur in backtick command strings.
Previously, text between backquotes in a psql metacommand's arguments
was always passed to the shell literally. That considerably hobbles
the usefulness of the feature for scripting, so we'd foreseen for a long
time that we'd someday want to allow substitution of psql variables into
the shell command. IMO the addition of \if metacommands has brought us to
that point, since \if can greatly benefit from some sort of client-side
expression evaluation capability, and psql itself is not going to grow any
such thing in time for v10. Hence, this patch. It allows :VARIABLE to be
replaced by the exact contents of the named variable, while :'VARIABLE'
is replaced by the variable's contents suitably quoted to become a single
shell-command argument. (The quoting rules for that are different from
those for SQL literals, so this is a bit of an abuse of the :'VARIABLE'
notation, but I doubt anyone will be confused.)
As with other situations in psql, no substitution occurs if the word
following a colon is not a known variable name. That limits the risk of
compatibility problems for existing psql scripts; but the risk isn't zero,
so this needs to be called out in the v10 release notes.
Discussion: https://postgr.es/m/9561.1490895211@sss.pgh.pa.us
2017-04-02 03:44:54 +02:00
|
|
|
variable's 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
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>:'<replaceable>variable_name</replaceable>'</literal> form prints an
|
Allow psql variable substitution to occur in backtick command strings.
Previously, text between backquotes in a psql metacommand's arguments
was always passed to the shell literally. That considerably hobbles
the usefulness of the feature for scripting, so we'd foreseen for a long
time that we'd someday want to allow substitution of psql variables into
the shell command. IMO the addition of \if metacommands has brought us to
that point, since \if can greatly benefit from some sort of client-side
expression evaluation capability, and psql itself is not going to grow any
such thing in time for v10. Hence, this patch. It allows :VARIABLE to be
replaced by the exact contents of the named variable, while :'VARIABLE'
is replaced by the variable's contents suitably quoted to become a single
shell-command argument. (The quoting rules for that are different from
those for SQL literals, so this is a bit of an abuse of the :'VARIABLE'
notation, but I doubt anyone will be confused.)
As with other situations in psql, no substitution occurs if the word
following a colon is not a known variable name. That limits the risk of
compatibility problems for existing psql scripts; but the risk isn't zero,
so this needs to be called out in the v10 release notes.
Discussion: https://postgr.es/m/9561.1490895211@sss.pgh.pa.us
2017-04-02 03:44:54 +02:00
|
|
|
error message and does not substitute the variable value when such
|
|
|
|
characters appear in the value.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Some commands take an <acronym>SQL</acronym> identifier (such as a
|
|
|
|
table name) as argument. These arguments follow the syntax rules
|
|
|
|
of <acronym>SQL</acronym>: Unquoted letters are forced to
|
2017-10-09 03:44:17 +02:00
|
|
|
lowercase, while double quotes (<literal>"</literal>) protect letters
|
2003-03-24 15:32:51 +01:00
|
|
|
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,
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>FOO"BAR"BAZ</literal> is interpreted as <literal>fooBARbaz</literal>,
|
|
|
|
and <literal>"A weird"" name"</literal> becomes <literal>A weird"
|
|
|
|
name</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
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
|
2002-07-28 17:22:21 +02:00
|
|
|
sequence <literal>\\</literal> (two backslashes) marks the end of
|
2003-03-24 15:32:51 +01:00
|
|
|
arguments and continues parsing <acronym>SQL</acronym> commands, if
|
2002-07-28 17:22:21 +02:00
|
|
|
any. That way <acronym>SQL</acronym> and
|
|
|
|
<application>psql</application> 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.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2017-04-03 00:26:37 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Many of the meta-commands act on the <firstterm>current query buffer</firstterm>.
|
2017-04-03 00:26:37 +02:00
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
|
|
|
The following meta-commands are defined:
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<variablelist>
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-a">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\a</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
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 <command>\pset</command> for a
|
2005-01-04 04:58:16 +01:00
|
|
|
more general solution.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-bind">
|
2022-11-15 13:50:27 +01:00
|
|
|
<term><literal>\bind</literal> [ <replaceable class="parameter">parameter</replaceable> ] ... </term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets query parameters for the next query execution, with the
|
|
|
|
specified parameters passed for any parameter placeholders
|
|
|
|
(<literal>$1</literal> etc.).
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Example:
|
|
|
|
<programlisting>
|
|
|
|
INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This also works for query-execution commands besides
|
|
|
|
<literal>\g</literal>, such as <literal>\gx</literal> and
|
|
|
|
<literal>\gset</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This command causes the extended query protocol (see <xref
|
|
|
|
linkend="protocol-query-concepts"/>) to be used, unlike normal
|
|
|
|
<application>psql</application> operation, which uses the simple
|
|
|
|
query protocol. So this command can be useful to test the extended
|
|
|
|
query protocol from 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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-c-lc">
|
2016-08-08 16:07:46 +02:00
|
|
|
<term><literal>\c</literal> or <literal>\connect [ -reuse-previous=<replaceable class="parameter">on|off</replaceable> ] [ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] | <replaceable class="parameter">conninfo</replaceable> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Establishes a new connection to a <productname>PostgreSQL</productname>
|
psql: fix \connect with URIs and conninfo strings
This is the second try at this, after fcef1617295 failed miserably and
had to be reverted: as it turns out, libpq cannot depend on libpgcommon
after all. Instead of shuffling code in the master branch, make that one
just like 9.4 and accept the duplication. (This was all my own mistake,
not the patch submitter's).
psql was already accepting conninfo strings as the first parameter in
\connect, but the way it worked wasn't sane; some of the other
parameters would get the previous connection's values, causing it to
connect to a completely unexpected server or, more likely, not finding
any server at all because of completely wrong combinations of
parameters.
Fix by explicitely checking for a conninfo-looking parameter in the
dbname position; if one is found, use its complete specification rather
than mix with the other arguments. Also, change tab-completion to not
try to complete conninfo/URI-looking "dbnames" and document that
conninfos are accepted as first argument.
There was a weak consensus to backpatch this, because while the behavior
of using the dbname as a conninfo is nowhere documented for \connect, it
is reasonable to expect that it works because it does work in many other
contexts. Therefore this is backpatched all the way back to 9.0.
Author: David Fetter, Andrew Dunstan. Some editorialization by me
(probably earning a Gierth's "Sloppy" badge in the process.)
Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost,
Robert Haas, Andrew Dunstan.
2015-04-02 17:30:57 +02:00
|
|
|
server. The connection parameters to use can be specified either
|
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connection
parameters, but in fact it only re-uses the database name, user name,
host name (and possibly hostaddr, depending on version), and port.
This is problematic for assorted use cases. Notably, pg_dump[all]
emits "\connect databasename" commands which we would like to have
re-use all other parameters. If such a script is loaded in a psql run
that initially had "-d connstring" with some non-default parameters,
those other parameters would be lost, potentially causing connection
failure. (Thus, this is the same kind of bug addressed in commits
a45bc8a4f and 8e5793ab6, although the details are much different.)
To fix, redesign do_connect() so that it pulls out all properties
of the old PGconn using PQconninfo(), and then replaces individual
properties in that array. In the case where we don't wish to re-use
anything, get libpq's default settings using PQconndefaults() and
replace entries in that, so that we don't need different code paths
for the two cases.
This does result in an additional behavioral change for cases where
the original connection parameters allowed multiple hosts, say
"psql -h host1,host2", and the \connect request allows re-use of the
host setting. Because the previous coding relied on PQhost(), it
would only permit reconnection to the same host originally selected.
Although one can think of scenarios where that's a good thing, there
are others where it is not. Moreover, that behavior doesn't seem to
meet the principle of least surprise, nor was it documented; nor is
it even clear it was intended, since that coding long pre-dates the
addition of multi-host support to libpq. Hence, this patch is content
to drop it and re-use the host list as given.
Per Peter Eisentraut's comments on bug #16604. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
2020-10-21 22:18:40 +02:00
|
|
|
using a positional syntax (one or more of database name, user,
|
|
|
|
host, and port), or using a <replaceable>conninfo</replaceable>
|
|
|
|
connection string as detailed in
|
|
|
|
<xref linkend="libpq-connstring"/>. If no arguments are given, a
|
|
|
|
new connection is made using the same parameters as before.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connection
parameters, but in fact it only re-uses the database name, user name,
host name (and possibly hostaddr, depending on version), and port.
This is problematic for assorted use cases. Notably, pg_dump[all]
emits "\connect databasename" commands which we would like to have
re-use all other parameters. If such a script is loaded in a psql run
that initially had "-d connstring" with some non-default parameters,
those other parameters would be lost, potentially causing connection
failure. (Thus, this is the same kind of bug addressed in commits
a45bc8a4f and 8e5793ab6, although the details are much different.)
To fix, redesign do_connect() so that it pulls out all properties
of the old PGconn using PQconninfo(), and then replaces individual
properties in that array. In the case where we don't wish to re-use
anything, get libpq's default settings using PQconndefaults() and
replace entries in that, so that we don't need different code paths
for the two cases.
This does result in an additional behavioral change for cases where
the original connection parameters allowed multiple hosts, say
"psql -h host1,host2", and the \connect request allows re-use of the
host setting. Because the previous coding relied on PQhost(), it
would only permit reconnection to the same host originally selected.
Although one can think of scenarios where that's a good thing, there
are others where it is not. Moreover, that behavior doesn't seem to
meet the principle of least surprise, nor was it documented; nor is
it even clear it was intended, since that coding long pre-dates the
addition of multi-host support to libpq. Hence, this patch is content
to drop it and re-use the host list as given.
Per Peter Eisentraut's comments on bug #16604. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
2020-10-21 22:18:40 +02:00
|
|
|
Specifying any
|
2016-08-08 16:07:46 +02:00
|
|
|
of <replaceable class="parameter">dbname</replaceable>,
|
psql: fix \connect with URIs and conninfo strings
This is the second try at this, after fcef1617295 failed miserably and
had to be reverted: as it turns out, libpq cannot depend on libpgcommon
after all. Instead of shuffling code in the master branch, make that one
just like 9.4 and accept the duplication. (This was all my own mistake,
not the patch submitter's).
psql was already accepting conninfo strings as the first parameter in
\connect, but the way it worked wasn't sane; some of the other
parameters would get the previous connection's values, causing it to
connect to a completely unexpected server or, more likely, not finding
any server at all because of completely wrong combinations of
parameters.
Fix by explicitely checking for a conninfo-looking parameter in the
dbname position; if one is found, use its complete specification rather
than mix with the other arguments. Also, change tab-completion to not
try to complete conninfo/URI-looking "dbnames" and document that
conninfos are accepted as first argument.
There was a weak consensus to backpatch this, because while the behavior
of using the dbname as a conninfo is nowhere documented for \connect, it
is reasonable to expect that it works because it does work in many other
contexts. Therefore this is backpatched all the way back to 9.0.
Author: David Fetter, Andrew Dunstan. Some editorialization by me
(probably earning a Gierth's "Sloppy" badge in the process.)
Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost,
Robert Haas, Andrew Dunstan.
2015-04-02 17:30:57 +02:00
|
|
|
<replaceable class="parameter">username</replaceable>,
|
|
|
|
<replaceable class="parameter">host</replaceable> or
|
2016-08-08 16:07:46 +02:00
|
|
|
<replaceable class="parameter">port</replaceable>
|
|
|
|
as <literal>-</literal> is equivalent to omitting that parameter.
|
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connection
parameters, but in fact it only re-uses the database name, user name,
host name (and possibly hostaddr, depending on version), and port.
This is problematic for assorted use cases. Notably, pg_dump[all]
emits "\connect databasename" commands which we would like to have
re-use all other parameters. If such a script is loaded in a psql run
that initially had "-d connstring" with some non-default parameters,
those other parameters would be lost, potentially causing connection
failure. (Thus, this is the same kind of bug addressed in commits
a45bc8a4f and 8e5793ab6, although the details are much different.)
To fix, redesign do_connect() so that it pulls out all properties
of the old PGconn using PQconninfo(), and then replaces individual
properties in that array. In the case where we don't wish to re-use
anything, get libpq's default settings using PQconndefaults() and
replace entries in that, so that we don't need different code paths
for the two cases.
This does result in an additional behavioral change for cases where
the original connection parameters allowed multiple hosts, say
"psql -h host1,host2", and the \connect request allows re-use of the
host setting. Because the previous coding relied on PQhost(), it
would only permit reconnection to the same host originally selected.
Although one can think of scenarios where that's a good thing, there
are others where it is not. Moreover, that behavior doesn't seem to
meet the principle of least surprise, nor was it documented; nor is
it even clear it was intended, since that coding long pre-dates the
addition of multi-host support to libpq. Hence, this patch is content
to drop it and re-use the host list as given.
Per Peter Eisentraut's comments on bug #16604. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
2020-10-21 22:18:40 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
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 <replaceable>sslmode</replaceable>. By default,
|
|
|
|
parameters are re-used in the positional syntax, but not when
|
|
|
|
a <replaceable>conninfo</replaceable> string is given. Passing a
|
|
|
|
first argument of <literal>-reuse-previous=on</literal>
|
|
|
|
or <literal>-reuse-previous=off</literal> overrides that default. If
|
|
|
|
parameters are re-used, then any parameter not explicitly specified as
|
|
|
|
a positional parameter or in the <replaceable>conninfo</replaceable>
|
|
|
|
string is taken from the existing connection's parameters. An
|
|
|
|
exception is that if the <replaceable>host</replaceable> setting
|
|
|
|
is changed from its previous value using the positional syntax,
|
|
|
|
any <replaceable>hostaddr</replaceable> setting present in the
|
|
|
|
existing connection's parameters is dropped.
|
Clean up some unpleasant behaviors in psql's \connect command.
The check for whether to complain about not having an old connection
to get parameters from was seriously out of date: it had not been
rethought when we invented connstrings, nor when we invented the
-reuse-previous option. Replace it with a check that throws an
error if reuse-previous is active and we lack an old connection to
reuse. While that doesn't move the goalposts very far in terms of
easing reconnection after a server crash, at least it's consistent.
If the user specifies a connstring plus additional parameters
(which is invalid per the documentation), the extra parameters were
silently ignored. That seems like it could be really confusing,
so let's throw a syntax error instead.
Teach the connstring code path to re-use the old connection's password
in the same cases as the old-style-syntax code path would, ie if we
are reusing parameters and the values of username, host/hostaddr, and
port are not being changed. Document this behavior, too, since it was
unmentioned before. Also simplify the implementation a bit, giving
rise to two new and useful properties: if there's a "password=xxx" in
the connstring, we'll use it not ignore it, and by default (i.e.,
except with --no-password) we will prompt for a password if the
re-used password or connstring password doesn't work. The previous
code just failed if the re-used password didn't work.
Given the paucity of field complaints about these issues, I don't
think that they rise to the level of back-patchable bug fixes,
and in any case they might represent undesirable behavior changes
in minor releases. So no back-patch.
Discussion: https://postgr.es/m/235210.1603321144@sss.pgh.pa.us
2020-10-22 20:04:21 +02:00
|
|
|
Also, any password used for the existing connection will be re-used
|
|
|
|
only if the user, host, and port settings are not changed.
|
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connection
parameters, but in fact it only re-uses the database name, user name,
host name (and possibly hostaddr, depending on version), and port.
This is problematic for assorted use cases. Notably, pg_dump[all]
emits "\connect databasename" commands which we would like to have
re-use all other parameters. If such a script is loaded in a psql run
that initially had "-d connstring" with some non-default parameters,
those other parameters would be lost, potentially causing connection
failure. (Thus, this is the same kind of bug addressed in commits
a45bc8a4f and 8e5793ab6, although the details are much different.)
To fix, redesign do_connect() so that it pulls out all properties
of the old PGconn using PQconninfo(), and then replaces individual
properties in that array. In the case where we don't wish to re-use
anything, get libpq's default settings using PQconndefaults() and
replace entries in that, so that we don't need different code paths
for the two cases.
This does result in an additional behavioral change for cases where
the original connection parameters allowed multiple hosts, say
"psql -h host1,host2", and the \connect request allows re-use of the
host setting. Because the previous coding relied on PQhost(), it
would only permit reconnection to the same host originally selected.
Although one can think of scenarios where that's a good thing, there
are others where it is not. Moreover, that behavior doesn't seem to
meet the principle of least surprise, nor was it documented; nor is
it even clear it was intended, since that coding long pre-dates the
addition of multi-host support to libpq. Hence, this patch is content
to drop it and re-use the host list as given.
Per Peter Eisentraut's comments on bug #16604. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
2020-10-21 22:18:40 +02:00
|
|
|
When the command neither specifies nor reuses a particular parameter,
|
|
|
|
the <application>libpq</application> default is used.
|
psql: fix \connect with URIs and conninfo strings
This is the second try at this, after fcef1617295 failed miserably and
had to be reverted: as it turns out, libpq cannot depend on libpgcommon
after all. Instead of shuffling code in the master branch, make that one
just like 9.4 and accept the duplication. (This was all my own mistake,
not the patch submitter's).
psql was already accepting conninfo strings as the first parameter in
\connect, but the way it worked wasn't sane; some of the other
parameters would get the previous connection's values, causing it to
connect to a completely unexpected server or, more likely, not finding
any server at all because of completely wrong combinations of
parameters.
Fix by explicitely checking for a conninfo-looking parameter in the
dbname position; if one is found, use its complete specification rather
than mix with the other arguments. Also, change tab-completion to not
try to complete conninfo/URI-looking "dbnames" and document that
conninfos are accepted as first argument.
There was a weak consensus to backpatch this, because while the behavior
of using the dbname as a conninfo is nowhere documented for \connect, it
is reasonable to expect that it works because it does work in many other
contexts. Therefore this is backpatched all the way back to 9.0.
Author: David Fetter, Andrew Dunstan. Some editorialization by me
(probably earning a Gierth's "Sloppy" badge in the process.)
Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost,
Robert Haas, Andrew Dunstan.
2015-04-02 17:30:57 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If the new connection is successfully made, the previous
|
|
|
|
connection is closed.
|
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connection
parameters, but in fact it only re-uses the database name, user name,
host name (and possibly hostaddr, depending on version), and port.
This is problematic for assorted use cases. Notably, pg_dump[all]
emits "\connect databasename" commands which we would like to have
re-use all other parameters. If such a script is loaded in a psql run
that initially had "-d connstring" with some non-default parameters,
those other parameters would be lost, potentially causing connection
failure. (Thus, this is the same kind of bug addressed in commits
a45bc8a4f and 8e5793ab6, although the details are much different.)
To fix, redesign do_connect() so that it pulls out all properties
of the old PGconn using PQconninfo(), and then replaces individual
properties in that array. In the case where we don't wish to re-use
anything, get libpq's default settings using PQconndefaults() and
replace entries in that, so that we don't need different code paths
for the two cases.
This does result in an additional behavioral change for cases where
the original connection parameters allowed multiple hosts, say
"psql -h host1,host2", and the \connect request allows re-use of the
host setting. Because the previous coding relied on PQhost(), it
would only permit reconnection to the same host originally selected.
Although one can think of scenarios where that's a good thing, there
are others where it is not. Moreover, that behavior doesn't seem to
meet the principle of least surprise, nor was it documented; nor is
it even clear it was intended, since that coding long pre-dates the
addition of multi-host support to libpq. Hence, this patch is content
to drop it and re-use the host list as given.
Per Peter Eisentraut's comments on bug #16604. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
2020-10-21 22:18:40 +02:00
|
|
|
If the connection attempt fails (wrong user name, access
|
|
|
|
denied, etc.), the previous connection will be kept if
|
2020-10-23 23:07:15 +02:00
|
|
|
<application>psql</application> 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 <literal>\connect</literal> command is successfully
|
|
|
|
executed. This distinction was chosen as
|
2006-04-02 22:08:22 +02:00
|
|
|
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.
|
2020-10-23 23:07:15 +02:00
|
|
|
Note that whenever a <literal>\connect</literal> 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 <literal>\connect</literal> failure, no parameters
|
|
|
|
are allowed to be re-used later, since the script would likely be
|
|
|
|
expecting the values from the failed <literal>\connect</literal>
|
|
|
|
to be re-used.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
psql: fix \connect with URIs and conninfo strings
This is the second try at this, after fcef1617295 failed miserably and
had to be reverted: as it turns out, libpq cannot depend on libpgcommon
after all. Instead of shuffling code in the master branch, make that one
just like 9.4 and accept the duplication. (This was all my own mistake,
not the patch submitter's).
psql was already accepting conninfo strings as the first parameter in
\connect, but the way it worked wasn't sane; some of the other
parameters would get the previous connection's values, causing it to
connect to a completely unexpected server or, more likely, not finding
any server at all because of completely wrong combinations of
parameters.
Fix by explicitely checking for a conninfo-looking parameter in the
dbname position; if one is found, use its complete specification rather
than mix with the other arguments. Also, change tab-completion to not
try to complete conninfo/URI-looking "dbnames" and document that
conninfos are accepted as first argument.
There was a weak consensus to backpatch this, because while the behavior
of using the dbname as a conninfo is nowhere documented for \connect, it
is reasonable to expect that it works because it does work in many other
contexts. Therefore this is backpatched all the way back to 9.0.
Author: David Fetter, Andrew Dunstan. Some editorialization by me
(probably earning a Gierth's "Sloppy" badge in the process.)
Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost,
Robert Haas, Andrew Dunstan.
2015-04-02 17:30:57 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Examples:
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
=> \c mydb myuser host.dom 6432
|
|
|
|
=> \c service=foo
|
|
|
|
=> \c "host=localhost port=5432 dbname=mydb connect_timeout=10 sslmode=disable"
|
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connection
parameters, but in fact it only re-uses the database name, user name,
host name (and possibly hostaddr, depending on version), and port.
This is problematic for assorted use cases. Notably, pg_dump[all]
emits "\connect databasename" commands which we would like to have
re-use all other parameters. If such a script is loaded in a psql run
that initially had "-d connstring" with some non-default parameters,
those other parameters would be lost, potentially causing connection
failure. (Thus, this is the same kind of bug addressed in commits
a45bc8a4f and 8e5793ab6, although the details are much different.)
To fix, redesign do_connect() so that it pulls out all properties
of the old PGconn using PQconninfo(), and then replaces individual
properties in that array. In the case where we don't wish to re-use
anything, get libpq's default settings using PQconndefaults() and
replace entries in that, so that we don't need different code paths
for the two cases.
This does result in an additional behavioral change for cases where
the original connection parameters allowed multiple hosts, say
"psql -h host1,host2", and the \connect request allows re-use of the
host setting. Because the previous coding relied on PQhost(), it
would only permit reconnection to the same host originally selected.
Although one can think of scenarios where that's a good thing, there
are others where it is not. Moreover, that behavior doesn't seem to
meet the principle of least surprise, nor was it documented; nor is
it even clear it was intended, since that coding long pre-dates the
addition of multi-host support to libpq. Hence, this patch is content
to drop it and re-use the host list as given.
Per Peter Eisentraut's comments on bug #16604. Back-patch to all
supported branches.
Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
2020-10-21 22:18:40 +02:00
|
|
|
=> \c -reuse-previous=on sslmode=require -- changes only sslmode
|
psql: fix \connect with URIs and conninfo strings
This is the second try at this, after fcef1617295 failed miserably and
had to be reverted: as it turns out, libpq cannot depend on libpgcommon
after all. Instead of shuffling code in the master branch, make that one
just like 9.4 and accept the duplication. (This was all my own mistake,
not the patch submitter's).
psql was already accepting conninfo strings as the first parameter in
\connect, but the way it worked wasn't sane; some of the other
parameters would get the previous connection's values, causing it to
connect to a completely unexpected server or, more likely, not finding
any server at all because of completely wrong combinations of
parameters.
Fix by explicitely checking for a conninfo-looking parameter in the
dbname position; if one is found, use its complete specification rather
than mix with the other arguments. Also, change tab-completion to not
try to complete conninfo/URI-looking "dbnames" and document that
conninfos are accepted as first argument.
There was a weak consensus to backpatch this, because while the behavior
of using the dbname as a conninfo is nowhere documented for \connect, it
is reasonable to expect that it works because it does work in many other
contexts. Therefore this is backpatched all the way back to 9.0.
Author: David Fetter, Andrew Dunstan. Some editorialization by me
(probably earning a Gierth's "Sloppy" badge in the process.)
Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost,
Robert Haas, Andrew Dunstan.
2015-04-02 17:30:57 +02:00
|
|
|
=> \c postgresql://tom@localhost/mydb?application_name=myapp
|
|
|
|
</programlisting>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-c-uc">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>\C [ <replaceable class="parameter">title</replaceable> ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the title of any tables being printed as the result of a
|
|
|
|
query or unset any such title. This command is equivalent to
|
|
|
|
<literal>\pset title <replaceable
|
|
|
|
class="parameter">title</replaceable></literal>. (The name of
|
|
|
|
this command derives from <quote>caption</quote>, as it was
|
|
|
|
previously only used to set the caption in an
|
|
|
|
<acronym>HTML</acronym> table.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-cd">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>\cd [ <replaceable>directory</replaceable> ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Changes the current working directory to
|
|
|
|
<replaceable>directory</replaceable>. Without argument, changes
|
|
|
|
to the current user's home directory.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
To print your current working directory, use <literal>\! pwd</literal>.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-conninfo">
|
2010-07-20 05:54:19 +02:00
|
|
|
<term><literal>\conninfo</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2010-08-03 20:33:09 +02:00
|
|
|
Outputs information about the current database connection.
|
2010-07-20 05:54:19 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<varlistentry id="app-psql-meta-commands-copy">
|
2020-07-18 03:42:41 +02:00
|
|
|
<term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] }
|
|
|
|
<literal>from</literal>
|
|
|
|
{ <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdin | pstdin }
|
|
|
|
[ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
|
|
|
|
[ where <replaceable class="parameter">condition</replaceable> ]</literal></term>
|
|
|
|
|
2006-08-31 01:34:22 +02:00
|
|
|
<term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) }
|
2020-07-18 03:42:41 +02:00
|
|
|
<literal>to</literal>
|
|
|
|
{ <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdout | pstdout }
|
2012-09-06 23:00:03 +02:00
|
|
|
[ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]</literal></term>
|
2000-02-20 15:29:21 +01:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-07-28 17:22:21 +02:00
|
|
|
Performs a frontend (client) copy. This is an operation that
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
runs an <acronym>SQL</acronym> <link linkend="sql-copy"><command>COPY</command></link>
|
2010-04-03 09:23:02 +02:00
|
|
|
command, but instead of the server
|
2002-10-19 02:22:14 +02:00
|
|
|
reading or writing the specified file,
|
2002-07-28 17:22:21 +02:00
|
|
|
<application>psql</application> reads or writes the file and
|
2003-03-24 15:32:51 +01:00
|
|
|
routes the data between the server and the local file system.
|
2004-01-21 00:48:56 +01:00
|
|
|
This means that file accessibility and privileges are those of
|
|
|
|
the local user, not the server, and no SQL superuser
|
|
|
|
privileges are required.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When <literal>program</literal> is specified,
|
Add support for piping COPY to/from an external program.
This includes backend "COPY TO/FROM PROGRAM '...'" syntax, and corresponding
psql \copy syntax. Like with reading/writing files, the backend version is
superuser-only, and in the psql version, the program is run in the client.
In the passing, the psql \copy STDIN/STDOUT syntax is subtly changed: if you
the stdin/stdout is quoted, it's now interpreted as a filename. For example,
"\copy foo from 'stdin'" now reads from a file called 'stdin', not from
standard input. Before this, there was no way to specify a filename called
stdin, stdout, pstdin or pstdout.
This creates a new function in pgport, wait_result_to_str(), which can
be used to convert the exit status of a process, as returned by wait(3),
to a human-readable string.
Etsuro Fujita, reviewed by Amit Kapila.
2013-02-27 17:17:21 +01:00
|
|
|
<replaceable class="parameter">command</replaceable> is
|
2014-03-13 18:49:03 +01:00
|
|
|
executed by <application>psql</application> and the data passed from
|
Add support for piping COPY to/from an external program.
This includes backend "COPY TO/FROM PROGRAM '...'" syntax, and corresponding
psql \copy syntax. Like with reading/writing files, the backend version is
superuser-only, and in the psql version, the program is run in the client.
In the passing, the psql \copy STDIN/STDOUT syntax is subtly changed: if you
the stdin/stdout is quoted, it's now interpreted as a filename. For example,
"\copy foo from 'stdin'" now reads from a file called 'stdin', not from
standard input. Before this, there was no way to specify a filename called
stdin, stdout, pstdin or pstdout.
This creates a new function in pgport, wait_result_to_str(), which can
be used to convert the exit status of a process, as returned by wait(3),
to a human-readable string.
Etsuro Fujita, reviewed by Amit Kapila.
2013-02-27 17:17:21 +01:00
|
|
|
or to <replaceable class="parameter">command</replaceable> is
|
|
|
|
routed between the server and the client.
|
2014-03-13 18:49:03 +01:00
|
|
|
Again, the execution privileges are those of
|
Add support for piping COPY to/from an external program.
This includes backend "COPY TO/FROM PROGRAM '...'" syntax, and corresponding
psql \copy syntax. Like with reading/writing files, the backend version is
superuser-only, and in the psql version, the program is run in the client.
In the passing, the psql \copy STDIN/STDOUT syntax is subtly changed: if you
the stdin/stdout is quoted, it's now interpreted as a filename. For example,
"\copy foo from 'stdin'" now reads from a file called 'stdin', not from
standard input. Before this, there was no way to specify a filename called
stdin, stdout, pstdin or pstdout.
This creates a new function in pgport, wait_result_to_str(), which can
be used to convert the exit status of a process, as returned by wait(3),
to a human-readable string.
Etsuro Fujita, reviewed by Amit Kapila.
2013-02-27 17:17:21 +01:00
|
|
|
the local user, not the server, and no SQL superuser
|
|
|
|
privileges are required.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
2014-03-13 18:49:03 +01:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
For <literal>\copy ... from stdin</literal>, data rows are read from the same
|
2014-03-13 18:49:03 +01:00
|
|
|
source that issued the command, continuing until <literal>\.</literal>
|
2017-10-09 03:44:17 +02:00
|
|
|
is read or the stream reaches <acronym>EOF</acronym>. This option is useful
|
2021-06-11 03:38:04 +02:00
|
|
|
for populating tables in-line within an SQL script file.
|
2017-10-09 03:44:17 +02:00
|
|
|
For <literal>\copy ... to stdout</literal>, output is sent to the same place
|
|
|
|
as <application>psql</application> command output, and
|
|
|
|
the <literal>COPY <replaceable>count</replaceable></literal> command status is
|
2014-03-13 18:49:03 +01:00
|
|
|
not printed (since it might be confused with a data row).
|
|
|
|
To read/write <application>psql</application>'s standard input or
|
2017-10-09 03:44:17 +02:00
|
|
|
output regardless of the current command source or <literal>\o</literal>
|
|
|
|
option, write <literal>from pstdin</literal> or <literal>to pstdout</literal>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2004-01-21 00:48:56 +01:00
|
|
|
|
Add support for piping COPY to/from an external program.
This includes backend "COPY TO/FROM PROGRAM '...'" syntax, and corresponding
psql \copy syntax. Like with reading/writing files, the backend version is
superuser-only, and in the psql version, the program is run in the client.
In the passing, the psql \copy STDIN/STDOUT syntax is subtly changed: if you
the stdin/stdout is quoted, it's now interpreted as a filename. For example,
"\copy foo from 'stdin'" now reads from a file called 'stdin', not from
standard input. Before this, there was no way to specify a filename called
stdin, stdout, pstdin or pstdout.
This creates a new function in pgport, wait_result_to_str(), which can
be used to convert the exit status of a process, as returned by wait(3),
to a human-readable string.
Etsuro Fujita, reviewed by Amit Kapila.
2013-02-27 17:17:21 +01:00
|
|
|
<para>
|
2014-03-13 18:49:03 +01:00
|
|
|
The syntax of this command is similar to that of the
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<acronym>SQL</acronym> <link linkend="sql-copy"><command>COPY</command></link>
|
2014-03-13 18:49:03 +01:00
|
|
|
command. All options other than the data source/destination are
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
as specified for <command>COPY</command>.
|
2017-10-09 03:44:17 +02:00
|
|
|
Because of this, special parsing rules apply to the <command>\copy</command>
|
2017-04-03 01:01:53 +02:00
|
|
|
meta-command. Unlike most other meta-commands, the entire remainder
|
2017-10-09 03:44:17 +02:00
|
|
|
of the line is always taken to be the arguments of <command>\copy</command>,
|
2017-04-03 01:01:53 +02:00
|
|
|
and neither variable interpolation nor backquote expansion are
|
|
|
|
performed in the arguments.
|
Add support for piping COPY to/from an external program.
This includes backend "COPY TO/FROM PROGRAM '...'" syntax, and corresponding
psql \copy syntax. Like with reading/writing files, the backend version is
superuser-only, and in the psql version, the program is run in the client.
In the passing, the psql \copy STDIN/STDOUT syntax is subtly changed: if you
the stdin/stdout is quoted, it's now interpreted as a filename. For example,
"\copy foo from 'stdin'" now reads from a file called 'stdin', not from
standard input. Before this, there was no way to specify a filename called
stdin, stdout, pstdin or pstdout.
This creates a new function in pgport, wait_result_to_str(), which can
be used to convert the exit status of a process, as returned by wait(3),
to a human-readable string.
Etsuro Fujita, reviewed by Amit Kapila.
2013-02-27 17:17:21 +01:00
|
|
|
</para>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
2019-01-26 20:15:42 +01:00
|
|
|
Another way to obtain the same result as <literal>\copy
|
|
|
|
... to</literal> is to use the <acronym>SQL</acronym> <literal>COPY
|
|
|
|
... TO STDOUT</literal> command and terminate it
|
|
|
|
with <literal>\g <replaceable>filename</replaceable></literal>
|
|
|
|
or <literal>\g |<replaceable>program</replaceable></literal>.
|
|
|
|
Unlike <literal>\copy</literal>, this method allows the command to
|
|
|
|
span multiple lines; also, variable interpolation and backquote
|
|
|
|
expansion can be used.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
These operations are not as efficient as the <acronym>SQL</acronym>
|
|
|
|
<command>COPY</command> 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 <acronym>SQL</acronym>
|
|
|
|
command might be preferable.
|
2023-11-03 18:57:59 +01:00
|
|
|
Also, because of this pass-through method, <literal>\copy
|
|
|
|
... from</literal> in <acronym>CSV</acronym> mode will erroneously
|
|
|
|
treat a <literal>\.</literal> data value alone on a line as an
|
|
|
|
end-of-input marker.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</tip>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-copyright">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\copyright</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-07-28 17:22:21 +02:00
|
|
|
Shows the copyright and distribution terms of
|
2004-08-24 02:06:51 +02:00
|
|
|
<productname>PostgreSQL</productname>.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2016-04-13 17:49:47 +02:00
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<varlistentry id="app-psql-meta-commands-crosstabview">
|
2016-04-09 01:23:18 +02:00
|
|
|
<term><literal>\crosstabview [
|
|
|
|
<replaceable class="parameter">colV</replaceable>
|
2016-04-15 04:54:26 +02:00
|
|
|
[ <replaceable class="parameter">colH</replaceable>
|
|
|
|
[ <replaceable class="parameter">colD</replaceable>
|
|
|
|
[ <replaceable class="parameter">sortcolH</replaceable>
|
|
|
|
] ] ] ] </literal></term>
|
2016-04-09 01:23:18 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-04-13 17:49:47 +02:00
|
|
|
Executes the current query buffer (like <literal>\g</literal>) and
|
|
|
|
shows the results in a crosstab grid.
|
2016-04-09 01:23:18 +02:00
|
|
|
The query must return at least three columns.
|
2017-10-09 03:44:17 +02:00
|
|
|
The output column identified by <replaceable class="parameter">colV</replaceable>
|
2016-04-13 17:49:47 +02:00
|
|
|
becomes a vertical header and the output column identified by
|
|
|
|
<replaceable class="parameter">colH</replaceable>
|
2016-04-15 04:54:26 +02:00
|
|
|
becomes a horizontal header.
|
2016-04-13 17:49:47 +02:00
|
|
|
<replaceable class="parameter">colD</replaceable> identifies
|
|
|
|
the output column to display within the grid.
|
2016-04-15 04:54:26 +02:00
|
|
|
<replaceable class="parameter">sortcolH</replaceable> identifies
|
|
|
|
an optional sort column for the horizontal header.
|
2016-04-09 01:23:18 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2016-04-13 17:49:47 +02:00
|
|
|
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,
|
|
|
|
<replaceable class="parameter">colV</replaceable> is taken as column 1
|
|
|
|
and <replaceable class="parameter">colH</replaceable> as column 2.
|
2016-04-09 01:23:18 +02:00
|
|
|
<replaceable class="parameter">colH</replaceable> must differ from
|
|
|
|
<replaceable class="parameter">colV</replaceable>.
|
2016-04-15 04:54:26 +02:00
|
|
|
If <replaceable class="parameter">colD</replaceable> is not
|
|
|
|
specified, then there must be exactly three columns in the query
|
|
|
|
result, and the column that is neither
|
|
|
|
<replaceable class="parameter">colV</replaceable> nor
|
|
|
|
<replaceable class="parameter">colH</replaceable>
|
|
|
|
is taken to be <replaceable class="parameter">colD</replaceable>.
|
2016-04-09 01:23:18 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2016-04-13 17:49:47 +02:00
|
|
|
The vertical header, displayed as the leftmost column, contains the
|
2017-10-09 03:44:17 +02:00
|
|
|
values found in column <replaceable class="parameter">colV</replaceable>, in the
|
2016-04-13 17:49:47 +02:00
|
|
|
same order as in the query results, but with duplicates removed.
|
2016-04-09 01:23:18 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2016-04-13 17:49:47 +02:00
|
|
|
The horizontal header, displayed as the first row, contains the values
|
|
|
|
found in column <replaceable class="parameter">colH</replaceable>,
|
|
|
|
with duplicates removed. By default, these appear in the same order
|
|
|
|
as in the query results. But if the
|
2017-10-09 03:44:17 +02:00
|
|
|
optional <replaceable class="parameter">sortcolH</replaceable> argument is given,
|
2016-04-15 04:54:26 +02:00
|
|
|
it identifies a column whose values must be integer numbers, and the
|
2016-04-13 17:49:47 +02:00
|
|
|
values from <replaceable class="parameter">colH</replaceable> will
|
|
|
|
appear in the horizontal header sorted according to the
|
2017-10-09 03:44:17 +02:00
|
|
|
corresponding <replaceable class="parameter">sortcolH</replaceable> values.
|
2016-04-09 01:23:18 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2016-04-13 17:49:47 +02:00
|
|
|
Inside the crosstab grid, for each distinct value <literal>x</literal>
|
|
|
|
of <replaceable class="parameter">colH</replaceable> and each distinct
|
|
|
|
value <literal>y</literal>
|
|
|
|
of <replaceable class="parameter">colV</replaceable>, the cell located
|
|
|
|
at the intersection <literal>(x,y)</literal> contains the value of
|
|
|
|
the <literal>colD</literal> column in the query result row for which
|
|
|
|
the value of <replaceable class="parameter">colH</replaceable>
|
|
|
|
is <literal>x</literal> and the value
|
|
|
|
of <replaceable class="parameter">colV</replaceable>
|
2017-10-09 03:44:17 +02:00
|
|
|
is <literal>y</literal>. If there is no such row, the cell is empty. If
|
2016-04-13 17:49:47 +02:00
|
|
|
there are multiple such rows, an error is reported.
|
2016-04-09 01:23:18 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2016-04-13 17:49:47 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-d">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\d[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-06-20 00:32:22 +02:00
|
|
|
For each relation (table, view, materialized view, index, sequence,
|
|
|
|
or foreign table)
|
2011-06-14 22:44:01 +02:00
|
|
|
or composite type matching the
|
2004-06-18 08:14:31 +02:00
|
|
|
<replaceable class="parameter">pattern</replaceable>, show all
|
2009-12-25 00:36:39 +01:00
|
|
|
columns, their types, the tablespace (if not the default) and any
|
|
|
|
special attributes such as <literal>NOT NULL</literal> or defaults.
|
|
|
|
Associated indexes, constraints, rules, and triggers are
|
2011-01-02 05:48:11 +01:00
|
|
|
also shown. For foreign tables, the associated foreign
|
|
|
|
server is shown as well.
|
2017-10-09 03:44:17 +02:00
|
|
|
(<quote>Matching the pattern</quote> is defined in
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<xref linkend="app-psql-patterns"/> below.)
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2011-08-05 19:24:03 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
For some types of relation, <literal>\d</literal> shows additional information
|
2017-06-20 00:32:22 +02:00
|
|
|
for each column: column values for sequences, indexed expressions for
|
|
|
|
indexes, and foreign data wrapper options for foreign tables.
|
2011-08-05 19:24:03 +02:00
|
|
|
</para>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
|
|
|
The command form <literal>\d+</literal> 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
|
2014-07-09 05:29:09 +02:00
|
|
|
table, the view definition if the relation is a view, a non-default
|
2020-09-03 12:38:32 +02:00
|
|
|
<link linkend="sql-altertable-replica-identity">replica
|
2020-09-02 09:59:22 +02:00
|
|
|
identity</link> setting and the
|
|
|
|
<link linkend="sql-create-access-method">access method</link> name
|
|
|
|
if the relation has an access method.
|
2009-04-04 02:39:14 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-04-02 17:15:32 +02:00
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
If <command>\d</command> is used without a
|
|
|
|
<replaceable class="parameter">pattern</replaceable> argument, it is
|
2017-06-20 00:32:22 +02:00
|
|
|
equivalent to <command>\dtvmsE</command> which will show a list of
|
|
|
|
all visible tables, views, materialized views, sequences and
|
|
|
|
foreign tables.
|
2011-01-02 05:48:11 +01:00
|
|
|
This is purely a convenience measure.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-da-lc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\da[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists aggregate functions, together with their
|
2007-03-16 09:28:01 +01:00
|
|
|
return type and the data types they operate on. If <replaceable
|
2003-03-24 15:32:51 +01:00
|
|
|
class="parameter">pattern</replaceable>
|
2003-07-23 17:05:42 +02:00
|
|
|
is specified, only aggregates whose names match the pattern are shown.
|
2009-04-02 17:15:32 +02:00
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-da-uc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dA[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2016-06-07 23:59:34 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists access methods. If <replaceable
|
|
|
|
class="parameter">pattern</replaceable> is specified, only access
|
|
|
|
methods whose names match the pattern are shown. If
|
|
|
|
<literal>+</literal> is appended to the command name, each access
|
|
|
|
method is listed with its associated handler function and description.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2003-01-07 21:56:07 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dac">
|
2020-03-08 11:32:25 +01:00
|
|
|
<term>
|
|
|
|
<literal>\dAc[+]
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">input-type-pattern</replaceable></link>]]
|
|
|
|
</literal>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists operator classes
|
2020-08-02 23:00:26 +02:00
|
|
|
(see <xref linkend="xindex-opclass"/>).
|
2020-04-14 07:45:43 +02:00
|
|
|
If <replaceable class="parameter">access-method-pattern</replaceable>
|
2020-03-08 11:32:25 +01:00
|
|
|
is specified, only operator classes associated with access methods whose
|
2020-08-02 23:00:26 +02:00
|
|
|
names match that pattern are listed.
|
2020-03-08 11:32:25 +01:00
|
|
|
If <replaceable class="parameter">input-type-pattern</replaceable>
|
|
|
|
is specified, only operator classes associated with input types whose
|
2020-08-02 23:00:26 +02:00
|
|
|
names match that pattern are listed.
|
2020-03-08 11:32:25 +01:00
|
|
|
If <literal>+</literal> is appended to the command name, each operator
|
|
|
|
class is listed with its associated operator family and owner.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-daf">
|
2020-03-08 11:32:25 +01:00
|
|
|
<term>
|
|
|
|
<literal>\dAf[+]
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">input-type-pattern</replaceable></link>]]
|
|
|
|
</literal>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists operator families
|
2020-08-02 23:00:26 +02:00
|
|
|
(see <xref linkend="xindex-opfamily"/>).
|
2020-04-14 07:45:43 +02:00
|
|
|
If <replaceable class="parameter">access-method-pattern</replaceable>
|
2020-03-08 11:32:25 +01:00
|
|
|
is specified, only operator families associated with access methods whose
|
2020-08-02 23:00:26 +02:00
|
|
|
names match that pattern are listed.
|
2020-03-08 11:32:25 +01:00
|
|
|
If <replaceable class="parameter">input-type-pattern</replaceable>
|
|
|
|
is specified, only operator families associated with input types whose
|
2020-08-02 23:00:26 +02:00
|
|
|
names match that pattern are listed.
|
2020-03-08 11:32:25 +01:00
|
|
|
If <literal>+</literal> is appended to the command name, each operator
|
|
|
|
family is listed with its owner.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dao">
|
2020-03-08 11:32:25 +01:00
|
|
|
<term>
|
|
|
|
<literal>\dAo[+]
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">operator-family-pattern</replaceable></link>]]
|
|
|
|
</literal>
|
|
|
|
</term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists operators associated with operator families
|
2020-08-02 23:00:26 +02:00
|
|
|
(see <xref linkend="xindex-strategies"/>).
|
2020-04-14 07:45:43 +02:00
|
|
|
If <replaceable class="parameter">access-method-pattern</replaceable>
|
2020-03-08 11:32:25 +01:00
|
|
|
is specified, only members of operator families associated with access
|
2020-08-02 23:00:26 +02:00
|
|
|
methods whose names match that pattern are listed.
|
|
|
|
If <replaceable class="parameter">operator-family-pattern</replaceable>
|
|
|
|
is specified, only members of operator families whose names match that
|
2020-03-08 11:32:25 +01:00
|
|
|
pattern are listed.
|
|
|
|
If <literal>+</literal> is appended to the command name, each operator
|
2020-08-02 23:00:26 +02:00
|
|
|
is listed with its sort operator family (if it is an ordering operator).
|
2020-03-08 11:32:25 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dap">
|
2020-03-08 11:32:25 +01:00
|
|
|
<term>
|
|
|
|
<literal>\dAp[+]
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">access-method-pattern</replaceable></link>
|
|
|
|
[<link linkend="app-psql-patterns"><replaceable class="parameter">operator-family-pattern</replaceable></link>]]
|
|
|
|
</literal>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-02 23:00:26 +02:00
|
|
|
Lists support functions associated with operator families
|
|
|
|
(see <xref linkend="xindex-support"/>).
|
2020-04-14 07:45:43 +02:00
|
|
|
If <replaceable class="parameter">access-method-pattern</replaceable>
|
2020-08-02 23:00:26 +02:00
|
|
|
is specified, only functions of operator families associated with
|
|
|
|
access methods whose names match that pattern are listed.
|
|
|
|
If <replaceable class="parameter">operator-family-pattern</replaceable>
|
|
|
|
is specified, only functions of operator families whose names match
|
|
|
|
that pattern are listed.
|
|
|
|
If <literal>+</literal> is appended to the command name, functions are
|
|
|
|
displayed verbosely, with their actual parameter lists.
|
2020-03-08 11:32:25 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-db">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\db[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists tablespaces. If <replaceable
|
2004-06-18 08:14:31 +02:00
|
|
|
class="parameter">pattern</replaceable>
|
|
|
|
is specified, only tablespaces whose names match the pattern are shown.
|
2014-07-15 19:59:53 +02:00
|
|
|
If <literal>+</literal> is appended to the command name, each tablespace
|
|
|
|
is listed with its associated options, on-disk size, permissions and
|
|
|
|
description.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dc-lc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dc[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2003-01-07 21:56:07 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists conversions between character-set encodings.
|
2004-06-18 08:14:31 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable>
|
2003-07-23 17:05:42 +02:00
|
|
|
is specified, only conversions whose names match the pattern are
|
2004-06-18 08:14:31 +02:00
|
|
|
listed.
|
2009-04-02 17:15:32 +02:00
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
2011-08-08 18:26:13 +02:00
|
|
|
If <literal>+</literal> is appended to the command name, each object
|
|
|
|
is listed with its associated description.
|
2003-01-07 21:56:07 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dconfig">
|
2022-04-07 23:09:44 +02:00
|
|
|
<term><literal>\dconfig[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists server configuration parameters and their values.
|
2022-04-11 21:11:46 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only parameters whose names match the pattern are listed. Without
|
|
|
|
a <replaceable class="parameter">pattern</replaceable>, only
|
|
|
|
parameters that are set to non-default values are listed.
|
|
|
|
(Use <literal>\dconfig *</literal> to see all parameters.)
|
2022-04-07 23:09:44 +02:00
|
|
|
If <literal>+</literal> 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).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dc-uc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dC[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2003-01-07 21:56:07 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists type casts.
|
2008-11-06 16:18:36 +01:00
|
|
|
If <replaceable class="parameter">pattern</replaceable>
|
|
|
|
is specified, only casts whose source or target types match the
|
|
|
|
pattern are listed.
|
2011-08-08 18:26:13 +02:00
|
|
|
If <literal>+</literal> is appended to the command name, each object
|
|
|
|
is listed with its associated description.
|
2003-01-07 21:56:07 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dd-lc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dd[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Shows the descriptions of objects of type <literal>constraint</literal>,
|
|
|
|
<literal>operator class</literal>, <literal>operator family</literal>,
|
|
|
|
<literal>rule</literal>, and <literal>trigger</literal>. All
|
2011-08-11 17:16:29 +02:00
|
|
|
other comments may be viewed by the respective backslash commands for
|
|
|
|
those object types.
|
|
|
|
</para>
|
|
|
|
|
2012-03-28 19:37:19 +02:00
|
|
|
<para><literal>\dd</literal> displays descriptions for objects matching the
|
2011-08-11 17:16:29 +02:00
|
|
|
<replaceable class="parameter">pattern</replaceable>, 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.
|
2009-04-02 17:15:32 +02:00
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
|
|
|
<para>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
Descriptions for objects can be created with the <link
|
|
|
|
linkend="sql-comment"><command>COMMENT</command></link>
|
2004-04-22 19:38:16 +02:00
|
|
|
<acronym>SQL</acronym> command.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dd-uc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dD[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2017-06-14 17:09:33 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists domains. If <replaceable
|
|
|
|
class="parameter">pattern</replaceable>
|
|
|
|
is specified, only domains whose names match the pattern are shown.
|
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
|
|
|
If <literal>+</literal> is appended to the command name, each object
|
|
|
|
is listed with its associated permissions and description.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-ddp">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\ddp [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2009-10-05 21:24:49 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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 <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only entries whose role name or schema name matches
|
|
|
|
the pattern are listed.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
The <link linkend="sql-alterdefaultprivileges"><command>ALTER DEFAULT
|
|
|
|
PRIVILEGES</command></link> command is used to set default access
|
|
|
|
privileges. The meaning of the privilege display is explained in
|
2018-12-03 17:40:49 +01:00
|
|
|
<xref linkend="ddl-priv"/>.
|
2009-10-05 21:24:49 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-de">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dE[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<term><literal>\di[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<term><literal>\dm[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<term><literal>\ds[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<term><literal>\dt[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<term><literal>\dv[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2011-05-22 14:13:17 +02:00
|
|
|
|
2011-01-02 05:48:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-05-22 14:13:17 +02:00
|
|
|
In this group of commands, the letters <literal>E</literal>,
|
2013-05-15 03:12:34 +02:00
|
|
|
<literal>i</literal>, <literal>m</literal>, <literal>s</literal>,
|
2011-05-22 14:13:17 +02:00
|
|
|
<literal>t</literal>, and <literal>v</literal>
|
2019-07-03 18:18:10 +02:00
|
|
|
stand for foreign table, index, materialized view,
|
|
|
|
sequence, table, and view,
|
2011-05-22 14:13:17 +02:00
|
|
|
respectively.
|
|
|
|
You can specify any or all of
|
|
|
|
these letters, in any order, to obtain a listing of objects
|
2019-07-03 18:18:10 +02:00
|
|
|
of these types. For example, <literal>\dti</literal> lists
|
|
|
|
tables and indexes. If <literal>+</literal> is
|
2011-05-22 14:13:17 +02:00
|
|
|
appended to the command name, each object is listed with its
|
2019-07-03 18:18:10 +02:00
|
|
|
persistence status (permanent, temporary, or unlogged),
|
|
|
|
physical size on disk, and associated description if any.
|
2011-01-02 05:48:11 +01:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
2011-05-22 14:13:17 +02:00
|
|
|
specified, only objects whose names match the pattern are listed.
|
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
2011-01-02 05:48:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-des">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\des[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2008-12-19 17:25:19 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists foreign servers (mnemonic: <quote>external
|
2008-12-19 17:25:19 +01:00
|
|
|
servers</quote>).
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only those servers whose name matches the pattern
|
|
|
|
are listed. If the form <literal>\des+</literal> is used, a
|
2010-08-17 06:37:21 +02:00
|
|
|
full description of each server is shown, including the
|
2018-12-03 17:40:49 +01:00
|
|
|
server's access privileges, type, version, options, and description.
|
2008-12-19 17:25:19 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-det">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\det[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2011-05-22 14:13:17 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists foreign tables (mnemonic: <quote>external tables</quote>).
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only entries whose table name or schema name matches
|
|
|
|
the pattern are listed. If the form <literal>\det+</literal>
|
2011-08-08 22:29:57 +02:00
|
|
|
is used, generic options and the foreign table description
|
|
|
|
are also displayed.
|
2011-05-22 14:13:17 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-deu">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\deu[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2008-12-19 17:25:19 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists user mappings (mnemonic: <quote>external
|
2008-12-19 17:25:19 +01:00
|
|
|
users</quote>).
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only those mappings whose user names match the
|
|
|
|
pattern are listed. If the form <literal>\deu+</literal> is
|
|
|
|
used, additional information about each mapping is shown.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<caution>
|
|
|
|
<para>
|
|
|
|
<literal>\deu+</literal> might also display the user name and
|
|
|
|
password of the remote user, so care should be taken not to
|
|
|
|
disclose them.
|
|
|
|
</para>
|
|
|
|
</caution>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dew">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dew[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2008-12-19 17:25:19 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists foreign-data wrappers (mnemonic: <quote>external
|
2008-12-19 17:25:19 +01:00
|
|
|
wrappers</quote>).
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only those foreign-data wrappers whose name matches
|
|
|
|
the pattern are listed. If the form <literal>\dew+</literal>
|
2018-12-03 17:40:49 +01:00
|
|
|
is used, the access privileges, options, and description of the
|
|
|
|
foreign-data wrapper are also shown.
|
2008-12-19 17:25:19 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-df-lc">
|
2021-04-08 05:02:16 +02:00
|
|
|
<term><literal>\df[anptwS+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> [ <replaceable class="parameter">arg_pattern</replaceable> ... ] ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-07-11 18:35:03 +02:00
|
|
|
Lists functions, together with their result data types, argument data
|
2017-10-09 03:44:17 +02:00
|
|
|
types, and function types, which are classified as <quote>agg</quote>
|
2018-07-14 12:17:49 +02:00
|
|
|
(aggregate), <quote>normal</quote>, <quote>procedure</quote>, <quote>trigger</quote>, or <quote>window</quote>.
|
2009-12-25 00:36:39 +01:00
|
|
|
To display only functions
|
2017-10-09 03:44:17 +02:00
|
|
|
of specific type(s), add the corresponding letters <literal>a</literal>,
|
2018-07-14 12:17:49 +02:00
|
|
|
<literal>n</literal>, <literal>p</literal>, <literal>t</literal>, or <literal>w</literal> to the command.
|
2009-12-25 00:36:39 +01:00
|
|
|
If <replaceable
|
2009-04-21 17:49:06 +02:00
|
|
|
class="parameter">pattern</replaceable> is specified, only
|
2014-01-16 21:29:18 +01:00
|
|
|
functions whose names match the pattern are shown.
|
2021-04-08 05:02:16 +02:00
|
|
|
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 <literal>-</literal> as
|
|
|
|
the last <replaceable class="parameter">arg_pattern</replaceable>.)
|
2014-01-16 21:29:18 +01:00
|
|
|
By default, only user-created
|
2009-12-25 00:36:39 +01:00
|
|
|
objects are shown; supply a pattern or the <literal>S</literal>
|
2009-04-21 17:49:06 +02:00
|
|
|
modifier to include system objects.
|
2014-01-16 21:29:18 +01:00
|
|
|
If the form <literal>\df+</literal> is used, additional information
|
2016-07-11 18:35:03 +02:00
|
|
|
about each function is shown, including volatility,
|
|
|
|
parallel safety, owner, security classification, access privileges,
|
2023-03-02 23:15:00 +01:00
|
|
|
language, internal name (for C and internal functions only),
|
|
|
|
and description.
|
|
|
|
Source code for a specific function can be seen
|
|
|
|
using <literal>\sf</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2002-08-23 03:27:44 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-df-uc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dF[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2007-08-22 06:45:20 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists text search configurations.
|
2007-08-22 06:45:20 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only configurations whose names match the pattern are shown.
|
|
|
|
If the form <literal>\dF+</literal> is used, a full description of
|
|
|
|
each configuration is shown, including the underlying text search
|
|
|
|
parser and the dictionary list for each parser token type.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dfd">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dFd[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2007-08-22 06:45:20 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists text search dictionaries.
|
2007-08-22 06:45:20 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only dictionaries whose names match the pattern are shown.
|
|
|
|
If the form <literal>\dFd+</literal> is used, additional information
|
|
|
|
is shown about each selected dictionary, including the underlying
|
|
|
|
text search template and the option values.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dfp">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dFp[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2007-08-22 06:45:20 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists text search parsers.
|
2007-08-22 06:45:20 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only parsers whose names match the pattern are shown.
|
|
|
|
If the form <literal>\dFp+</literal> is used, a full description of
|
|
|
|
each parser is shown, including the underlying functions and the
|
|
|
|
list of recognized token types.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dft">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dFt[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2007-08-22 06:45:20 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists text search templates.
|
2007-08-22 06:45:20 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only templates whose names match the pattern are shown.
|
|
|
|
If the form <literal>\dFt+</literal> is used, additional information
|
|
|
|
is shown about each template, including the underlying function names.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dg">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dg[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2003-12-01 23:21:54 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-03-22 07:08:25 +01:00
|
|
|
Lists database roles.
|
2017-10-09 03:44:17 +02:00
|
|
|
(Since the concepts of <quote>users</quote> and <quote>groups</quote> have been
|
|
|
|
unified into <quote>roles</quote>, this command is now equivalent to
|
2012-03-22 07:08:25 +01:00
|
|
|
<literal>\du</literal>.)
|
2016-04-08 22:56:27 +02:00
|
|
|
By default, only user-created roles are shown; supply the
|
|
|
|
<literal>S</literal> modifier to include system roles.
|
2012-03-22 07:08:25 +01:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only those roles whose names match the pattern are listed.
|
2009-10-05 21:24:49 +02:00
|
|
|
If the form <literal>\dg+</literal> is used, additional information
|
2012-03-22 07:08:25 +01:00
|
|
|
is shown about each role; currently this adds the comment for each
|
|
|
|
role.
|
2003-12-01 23:21:54 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dl-lc">
|
2022-01-06 19:09:05 +01:00
|
|
|
<term><literal>\dl[+]</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This is an alias for <command>\lo_list</command>, which shows a
|
|
|
|
list of large objects.
|
2022-01-06 19:09:05 +01:00
|
|
|
If <literal>+</literal> is appended to the command name,
|
|
|
|
each large object is listed with its associated permissions,
|
|
|
|
if any.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dl-uc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dL[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2011-01-20 06:00:30 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-04-09 20:08:41 +02:00
|
|
|
Lists procedural languages. If <replaceable
|
2011-01-20 06:00:30 +01:00
|
|
|
class="parameter">pattern</replaceable>
|
|
|
|
is specified, only languages whose names match the pattern are listed.
|
|
|
|
By default, only user-created languages
|
|
|
|
are shown; supply the <literal>S</literal> modifier to include system
|
|
|
|
objects. If <literal>+</literal> is appended to the command name, each
|
|
|
|
language is listed with its call handler, validator, access privileges,
|
|
|
|
and whether it is a system object.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2011-02-12 14:54:13 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dn">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dn[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2003-01-07 21:56:07 +01:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists schemas (namespaces). If <replaceable
|
|
|
|
class="parameter">pattern</replaceable>
|
2003-07-23 17:05:42 +02:00
|
|
|
is specified, only schemas whose names match the pattern are listed.
|
2010-11-07 02:41:14 +01:00
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system objects.
|
|
|
|
If <literal>+</literal> is appended to the command name, each object
|
|
|
|
is listed with its associated permissions and description, if any.
|
2003-01-07 21:56:07 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-do-lc">
|
2021-04-08 05:02:16 +02:00
|
|
|
<term><literal>\do[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> [ <replaceable class="parameter">arg_pattern</replaceable> [ <replaceable class="parameter">arg_pattern</replaceable> ] ] ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2014-01-16 21:29:18 +01:00
|
|
|
Lists operators with their operand and result types.
|
2004-06-18 08:14:31 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only operators whose names match the pattern are listed.
|
2021-04-08 05:02:16 +02:00
|
|
|
If one <replaceable class="parameter">arg_pattern</replaceable> is
|
|
|
|
specified, only prefix operators whose right argument's type name
|
|
|
|
matches that pattern are listed.
|
|
|
|
If two <replaceable class="parameter">arg_pattern</replaceable>s
|
|
|
|
are specified, only binary operators whose argument type names match
|
|
|
|
those patterns are listed. (Alternatively, write <literal>-</literal>
|
|
|
|
for the unused argument of a unary operator.)
|
2014-01-16 21:29:18 +01:00
|
|
|
By default, only user-created objects are shown; supply a
|
2009-04-02 17:15:32 +02:00
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
2014-01-16 21:29:18 +01:00
|
|
|
If <literal>+</literal> is appended to the command name,
|
|
|
|
additional information about each operator is shown, currently just
|
|
|
|
the name of the underlying function.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-do-uc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dO[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2011-02-12 14:54:13 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists collations.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only collations whose names match the pattern are
|
|
|
|
listed. By default, only user-created objects are shown;
|
|
|
|
supply a pattern or the <literal>S</literal> modifier to
|
|
|
|
include system objects. If <literal>+</literal> is appended
|
2011-04-09 20:08:41 +02:00
|
|
|
to the command name, each collation is listed with its associated
|
2011-02-12 14:54:13 +01:00
|
|
|
description, if any.
|
2011-04-09 20:08:41 +02:00
|
|
|
Note that only collations usable with the current database's encoding
|
|
|
|
are shown, so the results may vary in different databases of the
|
|
|
|
same installation.
|
2011-02-12 14:54:13 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dp-lc">
|
2023-01-07 12:09:26 +01:00
|
|
|
<term><literal>\dp[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists tables, views and sequences with their
|
2003-03-24 15:32:51 +01:00
|
|
|
associated access privileges.
|
2004-06-18 08:14:31 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
2009-12-25 00:36:39 +01:00
|
|
|
specified, only tables, views and sequences whose names match the
|
2023-01-07 12:09:26 +01:00
|
|
|
pattern are listed. By default only user-created objects are shown;
|
|
|
|
supply a pattern or the <literal>S</literal> modifier to include
|
|
|
|
system objects.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2002-08-10 05:56:24 +02:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
The <link linkend="sql-grant"><command>GRANT</command></link> and
|
|
|
|
<link linkend="sql-revoke"><command>REVOKE</command></link>
|
2009-10-05 21:24:49 +02:00
|
|
|
commands are used to set access privileges. The meaning of the
|
2018-12-03 17:40:49 +01:00
|
|
|
privilege display is explained in
|
|
|
|
<xref linkend="ddl-priv"/>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2019-04-07 13:59:12 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dp-uc">
|
2019-04-07 13:59:12 +02:00
|
|
|
<term><literal>\dP[itn+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists partitioned relations.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable>
|
|
|
|
is specified, only entries whose name matches the pattern are listed.
|
|
|
|
The modifiers <literal>t</literal> (tables) and <literal>i</literal>
|
|
|
|
(indexes) can be appended to the command, filtering the kind of
|
|
|
|
relations to list. By default, partitioned tables and indexes are
|
|
|
|
listed.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If the modifier <literal>n</literal> (<quote>nested</quote>) is used,
|
2019-04-18 00:35:41 +02:00
|
|
|
or a pattern is specified, then non-root partitioned relations are
|
2019-04-07 13:59:12 +02:00
|
|
|
included, and a column is shown displaying the parent of each
|
|
|
|
partitioned relation.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-04-18 00:35:41 +02:00
|
|
|
If <literal>+</literal> is appended to the command name, the sum of the
|
|
|
|
sizes of each relation's partitions is also displayed, along with the
|
|
|
|
relation's description.
|
2019-04-07 13:59:12 +02:00
|
|
|
If <literal>n</literal> is combined with <literal>+</literal>, 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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-07-19 18:46:30 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-drds">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\drds [ <link linkend="app-psql-patterns"><replaceable class="parameter">role-pattern</replaceable></link> [ <link linkend="app-psql-patterns"><replaceable class="parameter">database-pattern</replaceable></link> ] ]</literal></term>
|
2009-10-08 18:34:01 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists defined configuration settings. These settings can be
|
|
|
|
role-specific, database-specific, or both.
|
|
|
|
<replaceable>role-pattern</replaceable> and
|
|
|
|
<replaceable>database-pattern</replaceable> are used to select
|
|
|
|
specific roles and databases to list, respectively. If omitted, or if
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>*</literal> is specified, all settings are listed, including those
|
2009-12-25 00:36:39 +01:00
|
|
|
not role-specific or database-specific, respectively.
|
2009-10-08 18:34:01 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
The <link linkend="sql-alterrole"><command>ALTER ROLE</command></link> and
|
|
|
|
<link linkend="sql-alterdatabase"><command>ALTER DATABASE</command></link>
|
2009-12-25 00:36:39 +01:00
|
|
|
commands are used to define per-role and per-database configuration
|
|
|
|
settings.
|
2009-10-08 18:34:01 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-07-19 18:46:30 +02:00
|
|
|
|
|
|
|
<varlistentry id="app-psql-meta-command-drg">
|
|
|
|
<term><literal>\drg[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists information about each granted role membership, including
|
|
|
|
assigned options (<literal>ADMIN</literal>,
|
|
|
|
<literal>INHERIT</literal> and/or <literal>SET</literal>) and grantor.
|
|
|
|
See the <link linkend="sql-grant"><command>GRANT</command></link>
|
|
|
|
command for information about role memberships.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
By default, only grants to user-created roles are shown; supply the
|
|
|
|
<literal>S</literal> modifier to include system roles.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only grants to those roles whose names match the pattern are listed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-drp">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dRp[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2017-01-19 18:00:00 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists replication publications.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only those publications whose names match the pattern are
|
|
|
|
listed.
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
If <literal>+</literal> is appended to the command name, the tables and
|
|
|
|
schemas associated with each publication are shown as well.
|
2017-01-19 18:00:00 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-drs">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dRs[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2017-01-19 18:00:00 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists replication subscriptions.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only those subscriptions whose names match the pattern are
|
|
|
|
listed.
|
|
|
|
If <literal>+</literal> is appended to the command name, additional
|
|
|
|
properties of the subscriptions are shown.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dt">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dT[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists data types.
|
2009-04-04 02:39:14 +02:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is
|
|
|
|
specified, only types whose names match the pattern are listed.
|
|
|
|
If <literal>+</literal> is appended to the command name, each type is
|
2011-12-19 23:05:19 +01:00
|
|
|
listed with its internal name and size, its allowed values
|
2017-10-09 03:44:17 +02:00
|
|
|
if it is an <type>enum</type> type, and its associated permissions.
|
2009-04-02 17:15:32 +02:00
|
|
|
By default, only user-created objects are shown; supply a
|
|
|
|
pattern or the <literal>S</literal> modifier to include system
|
|
|
|
objects.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-du">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\du[S+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-03-22 07:08:25 +01:00
|
|
|
Lists database roles.
|
2017-10-09 03:44:17 +02:00
|
|
|
(Since the concepts of <quote>users</quote> and <quote>groups</quote> have been
|
|
|
|
unified into <quote>roles</quote>, this command is now equivalent to
|
2012-03-22 07:08:25 +01:00
|
|
|
<literal>\dg</literal>.)
|
2016-04-08 22:56:27 +02:00
|
|
|
By default, only user-created roles are shown; supply the
|
|
|
|
<literal>S</literal> modifier to include system roles.
|
2012-03-22 07:08:25 +01:00
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only those roles whose names match the pattern are listed.
|
2009-07-24 21:35:44 +02:00
|
|
|
If the form <literal>\du+</literal> is used, additional information
|
2012-03-22 07:08:25 +01:00
|
|
|
is shown about each role; currently this adds the comment for each
|
|
|
|
role.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dx-lc">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dx[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2011-02-08 22:08:41 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists installed extensions.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable>
|
|
|
|
is specified, only those extensions whose names match the pattern
|
|
|
|
are listed.
|
|
|
|
If the form <literal>\dx+</literal> is used, all the objects belonging
|
|
|
|
to each matching extension are listed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dx-uc">
|
2021-01-20 22:56:06 +01:00
|
|
|
<term><literal>\dX [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists extended statistics.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable>
|
|
|
|
is specified, only those extended statistics whose names match the
|
|
|
|
pattern are listed.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-04-09 06:53:07 +02:00
|
|
|
The status of each kind of extended statistics is shown in a column
|
|
|
|
named after its statistic kind (e.g. Ndistinct).
|
2021-09-29 04:56:13 +02:00
|
|
|
<literal>defined</literal> means that it was requested when creating
|
|
|
|
the statistics, and NULL means it wasn't requested.
|
|
|
|
You can use <structname>pg_stats_ext</structname> if you'd like to
|
|
|
|
know whether <link linkend="sql-analyze"><command>ANALYZE</command></link>
|
|
|
|
was run and statistics are available to the planner.
|
2021-01-20 22:56:06 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-dy">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\dy[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2012-07-18 16:16:16 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Lists event triggers.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable>
|
|
|
|
is specified, only those event triggers whose names match the pattern
|
|
|
|
are listed.
|
|
|
|
If <literal>+</literal> is appended to the command name, each object
|
|
|
|
is listed with its associated description.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-edit">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\e</literal> or <literal>\edit</literal> <literal> <optional> <replaceable class="parameter">filename</replaceable> </optional> <optional> <replaceable class="parameter">line_number</replaceable> </optional> </literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If <replaceable class="parameter">filename</replaceable> is
|
2017-04-03 00:26:37 +02:00
|
|
|
specified, the file is edited; after the editor exits, the file's
|
|
|
|
content is copied into the current query buffer. If no <replaceable
|
2010-08-12 02:40:59 +02:00
|
|
|
class="parameter">filename</replaceable> is given, the current query
|
|
|
|
buffer is copied to a temporary file which is then edited in the same
|
2017-04-03 00:26:37 +02:00
|
|
|
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
|
2010-08-12 02:40:59 +02:00
|
|
|
fashion.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2021-04-03 23:38:31 +02:00
|
|
|
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
|
2017-04-03 00:26:37 +02:00
|
|
|
the normal rules of <application>psql</application>, 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
|
2019-11-22 23:07:54 +01:00
|
|
|
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 <literal>\g</literal> to send it,
|
|
|
|
or <literal>\r</literal> to cancel it by clearing the query buffer.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-04-03 00:26:37 +02:00
|
|
|
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 <command>\i</command> for that.)
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<para>
|
2011-07-23 23:25:29 +02:00
|
|
|
If a line number is specified, <application>psql</application> will
|
|
|
|
position the cursor on the specified line of the file or query buffer.
|
|
|
|
Note that if a single all-digits argument is given,
|
|
|
|
<application>psql</application> assumes it is a line number,
|
|
|
|
not a file name.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2010-08-12 02:40:59 +02:00
|
|
|
|
2011-07-23 23:25:29 +02:00
|
|
|
<tip>
|
2010-08-12 02:40:59 +02:00
|
|
|
<para>
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
See <xref linkend="app-psql-environment"/>, below, for how to
|
|
|
|
configure and customize your editor.
|
2010-08-12 02:40:59 +02:00
|
|
|
</para>
|
2011-07-23 23:25:29 +02:00
|
|
|
</tip>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-echo">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>\echo <replaceable class="parameter">text</replaceable> [ ... ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-07-05 18:32:36 +02:00
|
|
|
Prints the evaluated arguments to standard output, separated by
|
|
|
|
spaces and followed by a newline. This can be useful to
|
2011-05-22 14:13:17 +02:00
|
|
|
intersperse information in the output of scripts. For example:
|
|
|
|
<programlisting>
|
|
|
|
=> <userinput>\echo `date`</userinput>
|
|
|
|
Tue Oct 26 21:40:57 CEST 1999
|
|
|
|
</programlisting>
|
|
|
|
If the first argument is an unquoted <literal>-n</literal> the trailing
|
2019-07-05 18:32:36 +02:00
|
|
|
newline is not written (nor is the first argument).
|
2011-05-22 14:13:17 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
If you use the <command>\o</command> command to redirect your
|
|
|
|
query output you might wish to use <command>\qecho</command>
|
2019-07-05 18:32:36 +02:00
|
|
|
instead of this command. See also <command>\warn</command>.
|
2011-05-22 14:13:17 +02:00
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-ef">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\ef <optional> <replaceable class="parameter">function_description</replaceable> <optional> <replaceable class="parameter">line_number</replaceable> </optional> </optional> </literal></term>
|
2008-09-06 02:01:25 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2018-02-13 16:34:04 +01:00
|
|
|
This command fetches and edits the definition of the named function or procedure,
|
|
|
|
in the form of a <command>CREATE OR REPLACE FUNCTION</command> or
|
|
|
|
<command>CREATE OR REPLACE PROCEDURE</command> command.
|
2017-10-09 03:44:17 +02:00
|
|
|
Editing is done in the same way as for <literal>\edit</literal>.
|
2021-04-03 23:38:31 +02:00
|
|
|
If you quit the editor without saving, the statement is discarded.
|
|
|
|
If you save and exit the editor, the updated command is executed immediately
|
2019-11-22 23:07:54 +01:00
|
|
|
if you added a semicolon to it. Otherwise it is redisplayed;
|
2017-10-09 03:44:17 +02:00
|
|
|
type semicolon or <literal>\g</literal> to send it, or <literal>\r</literal>
|
2008-09-06 02:01:25 +02:00
|
|
|
to cancel.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The target function can be specified by name alone, or by name
|
2017-10-09 03:44:17 +02:00
|
|
|
and arguments, for example <literal>foo(integer, text)</literal>.
|
2008-09-06 02:01:25 +02:00
|
|
|
The argument types must be given if there is more
|
|
|
|
than one function of the same name.
|
|
|
|
</para>
|
2008-09-06 22:18:08 +02:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If no function is specified, a blank <command>CREATE FUNCTION</command>
|
2008-09-06 22:18:08 +02:00
|
|
|
template is presented for editing.
|
|
|
|
</para>
|
2010-08-12 02:40:59 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
If a line number is specified, <application>psql</application> will
|
2011-07-23 23:25:29 +02:00
|
|
|
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.)
|
|
|
|
</para>
|
|
|
|
|
2017-04-03 01:01:53 +02:00
|
|
|
<para>
|
|
|
|
Unlike most other meta-commands, the entire remainder of the line is
|
2017-10-09 03:44:17 +02:00
|
|
|
always taken to be the argument(s) of <command>\ef</command>, and neither
|
2017-04-03 01:01:53 +02:00
|
|
|
variable interpolation nor backquote expansion are performed in the
|
|
|
|
arguments.
|
|
|
|
</para>
|
|
|
|
|
2011-07-23 23:25:29 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
See <xref linkend="app-psql-environment"/>, below, for how to
|
|
|
|
configure and customize your editor.
|
2010-08-12 02:40:59 +02:00
|
|
|
</para>
|
2011-07-23 23:25:29 +02:00
|
|
|
</tip>
|
2008-09-06 02:01:25 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-encoding">
|
2016-07-13 00:10:16 +02:00
|
|
|
<term><literal>\encoding [ <replaceable class="parameter">encoding</replaceable> ]</literal></term>
|
2015-07-03 21:48:18 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-07-13 00:10:16 +02:00
|
|
|
Sets the client character set encoding. Without an argument, this command
|
|
|
|
shows the current encoding.
|
2015-07-03 21:48:18 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-errverbose">
|
2016-07-13 00:10:16 +02:00
|
|
|
<term><literal>\errverbose</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-07-13 00:10:16 +02:00
|
|
|
Repeats the most recent server error message at maximum
|
|
|
|
verbosity, as though <varname>VERBOSITY</varname> were set
|
2017-10-09 03:44:17 +02:00
|
|
|
to <literal>verbose</literal> and <varname>SHOW_CONTEXT</varname> were
|
|
|
|
set to <literal>always</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-ev">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\ev <optional> <replaceable class="parameter">view_name</replaceable> <optional> <replaceable class="parameter">line_number</replaceable> </optional> </optional> </literal></term>
|
2016-04-03 18:29:55 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-07-13 00:10:16 +02:00
|
|
|
This command fetches and edits the definition of the named view,
|
2017-10-09 03:44:17 +02:00
|
|
|
in the form of a <command>CREATE OR REPLACE VIEW</command> command.
|
|
|
|
Editing is done in the same way as for <literal>\edit</literal>.
|
2021-04-03 23:38:31 +02:00
|
|
|
If you quit the editor without saving, the statement is discarded.
|
|
|
|
If you save and exit the editor, the updated command is executed immediately
|
2019-11-22 23:07:54 +01:00
|
|
|
if you added a semicolon to it. Otherwise it is redisplayed;
|
2017-10-09 03:44:17 +02:00
|
|
|
type semicolon or <literal>\g</literal> to send it, or <literal>\r</literal>
|
2016-07-13 00:10:16 +02:00
|
|
|
to cancel.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If no view is specified, a blank <command>CREATE VIEW</command>
|
2016-07-13 00:10:16 +02:00
|
|
|
template is presented for editing.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If a line number is specified, <application>psql</application> will
|
|
|
|
position the cursor on the specified line of the view definition.
|
2016-04-03 18:29:55 +02:00
|
|
|
</para>
|
2017-04-03 01:01:53 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Unlike most other meta-commands, the entire remainder of the line is
|
2017-10-09 03:44:17 +02:00
|
|
|
always taken to be the argument(s) of <command>\ev</command>, and neither
|
2017-04-03 01:01:53 +02:00
|
|
|
variable interpolation nor backquote expansion are performed in the
|
|
|
|
arguments.
|
|
|
|
</para>
|
2016-04-03 18:29:55 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-f">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\f [ <replaceable class="parameter">string</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-07-28 17:22:21 +02:00
|
|
|
Sets the field separator for unaligned query output. The default
|
2017-07-05 03:10:08 +02:00
|
|
|
is the vertical bar (<literal>|</literal>). It is equivalent to
|
|
|
|
<command>\pset fieldsep</command>.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-g">
|
2020-04-07 23:46:29 +02:00
|
|
|
<term><literal>\g [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
|
|
|
|
<term><literal>\g [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-04-03 00:26:37 +02:00
|
|
|
Sends the current query buffer to the server for execution.
|
2020-04-07 23:46:29 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If parentheses appear after <literal>\g</literal>, they surround a
|
|
|
|
space-separated list
|
|
|
|
of <replaceable class="parameter">option</replaceable><literal>=</literal><replaceable class="parameter">value</replaceable>
|
|
|
|
formatting-option clauses, which are interpreted in the same way
|
|
|
|
as <literal>\pset</literal>
|
|
|
|
<replaceable class="parameter">option</replaceable>
|
|
|
|
<replaceable class="parameter">value</replaceable> commands, but take
|
|
|
|
effect only for the duration of this query. In this list, spaces are
|
|
|
|
not allowed around <literal>=</literal> signs, but are required
|
|
|
|
between option clauses.
|
|
|
|
If <literal>=</literal><replaceable class="parameter">value</replaceable>
|
|
|
|
is omitted, the
|
|
|
|
named <replaceable class="parameter">option</replaceable> is changed
|
|
|
|
in the same way as for
|
|
|
|
<literal>\pset</literal> <replaceable class="parameter">option</replaceable>
|
|
|
|
with no explicit <replaceable class="parameter">value</replaceable>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If a <replaceable class="parameter">filename</replaceable>
|
|
|
|
or <literal>|</literal><replaceable class="parameter">command</replaceable>
|
|
|
|
argument is given, the query's output is written to the named
|
2017-04-03 00:26:37 +02:00
|
|
|
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.
|
2013-02-02 20:21:24 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2017-04-03 00:26:37 +02:00
|
|
|
If the current query buffer is empty, the most recently sent query is
|
|
|
|
re-executed instead. Except for that behavior, <literal>\g</literal>
|
2020-04-07 23:46:29 +02:00
|
|
|
without any arguments is essentially equivalent to a semicolon.
|
|
|
|
With arguments, <literal>\g</literal> provides
|
|
|
|
a <quote>one-shot</quote> alternative to the <command>\o</command>
|
|
|
|
command, and additionally allows one-shot adjustments of the
|
|
|
|
output formatting options normally set by <literal>\pset</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2017-04-03 01:01:53 +02:00
|
|
|
<para>
|
2020-04-07 23:46:29 +02:00
|
|
|
When the last argument begins with <literal>|</literal>, the entire
|
|
|
|
remainder of the line is taken to be
|
2017-04-03 01:01:53 +02:00
|
|
|
the <replaceable class="parameter">command</replaceable> 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.
|
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
2017-03-07 15:31:52 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-gdesc">
|
2017-09-06 00:17:47 +02:00
|
|
|
<term><literal>\gdesc</literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If the current query buffer is empty, the most recently sent query
|
|
|
|
is described instead.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-getenv">
|
2021-12-20 19:17:58 +01:00
|
|
|
<term><literal>\getenv <replaceable class="parameter">psql_var</replaceable> <replaceable class="parameter">env_var</replaceable></literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Gets the value of the environment
|
|
|
|
variable <replaceable class="parameter">env_var</replaceable>
|
|
|
|
and assigns it to the <application>psql</application>
|
|
|
|
variable <replaceable class="parameter">psql_var</replaceable>.
|
|
|
|
If <replaceable class="parameter">env_var</replaceable> is
|
|
|
|
not defined in the <application>psql</application> process's
|
|
|
|
environment, <replaceable class="parameter">psql_var</replaceable>
|
|
|
|
is not changed. Example:
|
|
|
|
<programlisting>
|
|
|
|
=> <userinput>\getenv home HOME</userinput>
|
|
|
|
=> <userinput>\echo :home</userinput>
|
|
|
|
/home/postgres
|
|
|
|
</programlisting></para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-gexec">
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
<term><literal>\gexec</literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-04-03 00:26:37 +02:00
|
|
|
Sends the current query buffer to the server, then treats
|
2021-06-11 03:38:04 +02:00
|
|
|
each column of each row of the query's output (if any) as an SQL
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
statement to be executed. For example, to create an index on each
|
2017-10-09 03:44:17 +02:00
|
|
|
column of <structname>my_table</structname>:
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
<programlisting>
|
2017-10-09 03:44:17 +02:00
|
|
|
=> <userinput>SELECT format('create index on my_table(%I)', attname)</userinput>
|
|
|
|
-> <userinput>FROM pg_attribute</userinput>
|
|
|
|
-> <userinput>WHERE attrelid = 'my_table'::regclass AND attnum > 0</userinput>
|
|
|
|
-> <userinput>ORDER BY attnum</userinput>
|
|
|
|
-> <userinput>\gexec</userinput>
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
CREATE INDEX
|
|
|
|
CREATE INDEX
|
|
|
|
CREATE INDEX
|
|
|
|
CREATE INDEX
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
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
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>psql</application> meta-commands nor contain <application>psql</application>
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
variable references. If any individual query fails, execution of
|
|
|
|
the remaining queries continues
|
|
|
|
unless <varname>ON_ERROR_STOP</varname> is set. Execution of each
|
|
|
|
query is subject to <varname>ECHO</varname> processing.
|
|
|
|
(Setting <varname>ECHO</varname> to <literal>all</literal>
|
|
|
|
or <literal>queries</literal> is often advisable when
|
2017-10-09 03:44:17 +02:00
|
|
|
using <command>\gexec</command>.) Query logging, single-step mode,
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
timing, and other query execution features apply to each generated
|
|
|
|
query as well.
|
|
|
|
</para>
|
2017-04-03 00:26:37 +02:00
|
|
|
<para>
|
|
|
|
If the current query buffer is empty, the most recently sent query
|
|
|
|
is re-executed instead.
|
|
|
|
</para>
|
Add a \gexec command to psql for evaluation of computed queries.
\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file. Now it can be done with no
intermediate step.
The implementation is fairly straightforward except for its interaction
with FETCH_COUNT. ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue). Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.
While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt. Perhaps that's a
back-patchable bug fix, but for now I just included it here.
Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
2016-04-04 21:25:16 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-gset">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\gset [ <replaceable class="parameter">prefix</replaceable> ]</literal></term>
|
2013-02-02 23:06:38 +01:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-04-03 00:26:37 +02:00
|
|
|
Sends the current query buffer to the server and stores the
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
query's output into <application>psql</application> variables
|
|
|
|
(see <xref linkend="app-psql-variables"/> below).
|
2013-02-02 23:06:38 +01:00
|
|
|
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:
|
|
|
|
<programlisting>
|
|
|
|
=> <userinput>SELECT 'hello' AS var1, 10 AS var2</userinput>
|
|
|
|
-> <userinput>\gset</userinput>
|
|
|
|
=> <userinput>\echo :var1 :var2</userinput>
|
|
|
|
hello 10
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If you specify a <replaceable class="parameter">prefix</replaceable>,
|
|
|
|
that string is prepended to the query's column names to create the
|
|
|
|
variable names to use:
|
|
|
|
<programlisting>
|
|
|
|
=> <userinput>SELECT 'hello' AS var1, 10 AS var2</userinput>
|
|
|
|
-> <userinput>\gset result_</userinput>
|
|
|
|
=> <userinput>\echo :result_var1 :result_var2</userinput>
|
|
|
|
hello 10
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If a column result is NULL, the corresponding variable is unset
|
|
|
|
rather than being set.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If the query fails or does not return one row,
|
|
|
|
no variables are changed.
|
|
|
|
</para>
|
2017-04-03 00:26:37 +02:00
|
|
|
<para>
|
|
|
|
If the current query buffer is empty, the most recently sent query
|
|
|
|
is re-executed instead.
|
|
|
|
</para>
|
2013-02-02 23:06:38 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-06-14 17:09:33 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-gx">
|
2020-04-07 23:46:29 +02:00
|
|
|
<term><literal>\gx [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
|
|
|
|
<term><literal>\gx [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
|
2017-06-14 17:09:33 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-04-07 23:46:29 +02:00
|
|
|
<literal>\gx</literal> is equivalent to <literal>\g</literal>, except
|
|
|
|
that it forces expanded output mode for this query, as
|
|
|
|
if <literal>expanded=on</literal> were included in the list of
|
|
|
|
<literal>\pset</literal> options. See also <literal>\x</literal>.
|
2017-06-14 17:09:33 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-help">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>\h</literal> or <literal>\help</literal> <literal>[ <replaceable class="parameter">command</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Gives syntax help on the specified <acronym>SQL</acronym>
|
2002-07-28 17:22:21 +02:00
|
|
|
command. If <replaceable class="parameter">command</replaceable>
|
|
|
|
is not specified, then <application>psql</application> will list
|
|
|
|
all the commands for which syntax help is available. If
|
|
|
|
<replaceable class="parameter">command</replaceable> is an
|
2003-03-24 15:32:51 +01:00
|
|
|
asterisk (<literal>*</literal>), then syntax help on all
|
2002-07-28 17:22:21 +02:00
|
|
|
<acronym>SQL</acronym> commands is shown.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2017-04-03 01:01:53 +02:00
|
|
|
<para>
|
|
|
|
Unlike most other meta-commands, the entire remainder of the line is
|
2017-10-09 03:44:17 +02:00
|
|
|
always taken to be the argument(s) of <command>\help</command>, and neither
|
2017-04-03 01:01:53 +02:00
|
|
|
variable interpolation nor backquote expansion are performed in the
|
|
|
|
arguments.
|
|
|
|
</para>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
To simplify typing, commands that consists of several words do
|
|
|
|
not have to be quoted. Thus it is fine to type <userinput>\help
|
|
|
|
alter table</userinput>.
|
|
|
|
</para>
|
|
|
|
</note>
|
1999-11-04 23:07:57 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-html">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\H</literal> or <literal>\html</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
Turns on <acronym>HTML</acronym> query output format. If the
|
|
|
|
<acronym>HTML</acronym> format is already on, it is switched
|
|
|
|
back to the default aligned text format. This command is for
|
|
|
|
compatibility and convenience, but see <command>\pset</command>
|
|
|
|
about setting other output options.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-include">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\i</literal> or <literal>\include</literal> <replaceable class="parameter">filename</replaceable></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-07-28 17:22:21 +02:00
|
|
|
Reads input from the file <replaceable
|
|
|
|
class="parameter">filename</replaceable> and executes it as
|
|
|
|
though it had been typed on the keyboard.
|
|
|
|
</para>
|
2015-12-14 05:42:54 +01:00
|
|
|
<para>
|
|
|
|
If <replaceable>filename</replaceable> is <literal>-</literal>
|
|
|
|
(hyphen), then standard input is read until an EOF indication
|
2017-10-09 03:44:17 +02:00
|
|
|
or <command>\q</command> meta-command. This can be used to intersperse
|
2015-12-14 05:42:54 +01:00
|
|
|
interactive input with input from files. Note that Readline behavior
|
|
|
|
will be used only if it is active at the outermost level.
|
|
|
|
</para>
|
2004-06-18 08:14:31 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
If you want to see the lines on the screen as they are read you
|
|
|
|
must set the variable <varname>ECHO</varname> to
|
|
|
|
<literal>all</literal>.
|
|
|
|
</para>
|
|
|
|
</note>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2018-03-22 15:42:03 +01:00
|
|
|
<varlistentry id="psql-metacommand-if">
|
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The control
structure feature per se is complete, but the boolean expressions
understood by \if and \elif are pretty primitive; basically, after
variable substitution and backtick expansion, the result has to be
"true" or "false" or one of the other standard spellings of a boolean
value. But that's enough for many purposes, since you can always
do the heavy lifting on the server side; and we can extend it later.
Along the way, pay down some of the technical debt that had built up
around psql/command.c:
* Refactor exec_command() into a function per command, instead of
being a 1500-line monstrosity. This makes the file noticeably longer
because of repetitive function header/trailer overhead, but it seems
much more readable.
* Teach psql_get_variable() and psqlscanslash.l to suppress variable
substitution and backtick expansion on the basis of the conditional
stack state, thereby allowing removal of the OT_NO_EVAL kluge.
* Fix the no-doubt-once-expedient hack of sometimes silently substituting
mainloop.c's previous_buf for query_buf when calling HandleSlashCmds.
(It's a bit remarkable that commands like \r worked at all with that.)
Recall of a previous query is now done explicitly in the slash commands
where that should happen.
Corey Huinker, reviewed by Fabien Coelho, further hacking by me
Discussion: https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com
2017-03-30 18:59:11 +02:00
|
|
|
<term><literal>\if</literal> <replaceable class="parameter">expression</replaceable></term>
|
|
|
|
<term><literal>\elif</literal> <replaceable class="parameter">expression</replaceable></term>
|
|
|
|
<term><literal>\else</literal></term>
|
|
|
|
<term><literal>\endif</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This group of commands implements nestable conditional blocks.
|
|
|
|
A conditional block must begin with an <command>\if</command> and end
|
|
|
|
with an <command>\endif</command>. In between there may be any number
|
|
|
|
of <command>\elif</command> clauses, which may optionally be followed
|
|
|
|
by a single <command>\else</command> clause. Ordinary queries and
|
|
|
|
other types of backslash commands may (and usually do) appear between
|
|
|
|
the commands forming a conditional block.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The <command>\if</command> and <command>\elif</command> commands read
|
2021-07-16 10:35:38 +02:00
|
|
|
their argument(s) and evaluate them as a Boolean expression. If the
|
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The control
structure feature per se is complete, but the boolean expressions
understood by \if and \elif are pretty primitive; basically, after
variable substitution and backtick expansion, the result has to be
"true" or "false" or one of the other standard spellings of a boolean
value. But that's enough for many purposes, since you can always
do the heavy lifting on the server side; and we can extend it later.
Along the way, pay down some of the technical debt that had built up
around psql/command.c:
* Refactor exec_command() into a function per command, instead of
being a 1500-line monstrosity. This makes the file noticeably longer
because of repetitive function header/trailer overhead, but it seems
much more readable.
* Teach psql_get_variable() and psqlscanslash.l to suppress variable
substitution and backtick expansion on the basis of the conditional
stack state, thereby allowing removal of the OT_NO_EVAL kluge.
* Fix the no-doubt-once-expedient hack of sometimes silently substituting
mainloop.c's previous_buf for query_buf when calling HandleSlashCmds.
(It's a bit remarkable that commands like \r worked at all with that.)
Recall of a previous query is now done explicitly in the slash commands
where that should happen.
Corey Huinker, reviewed by Fabien Coelho, further hacking by me
Discussion: https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com
2017-03-30 18:59:11 +02:00
|
|
|
expression yields <literal>true</literal> then processing continues
|
|
|
|
normally; otherwise, lines are skipped until a
|
|
|
|
matching <command>\elif</command>, <command>\else</command>,
|
|
|
|
or <command>\endif</command> is reached. Once
|
|
|
|
an <command>\if</command> or <command>\elif</command> test has
|
|
|
|
succeeded, the arguments of later <command>\elif</command> commands in
|
|
|
|
the same block are not evaluated but are treated as false. Lines
|
|
|
|
following an <command>\else</command> are processed only if no earlier
|
|
|
|
matching <command>\if</command> or <command>\elif</command> succeeded.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The <replaceable class="parameter">expression</replaceable> argument
|
|
|
|
of an <command>\if</command> or <command>\elif</command> 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:
|
|
|
|
<literal>true</literal>, <literal>false</literal>, <literal>1</literal>,
|
|
|
|
<literal>0</literal>, <literal>on</literal>, <literal>off</literal>,
|
|
|
|
<literal>yes</literal>, <literal>no</literal>. For example,
|
|
|
|
<literal>t</literal>, <literal>T</literal>, and <literal>tR</literal>
|
|
|
|
will all be considered to be <literal>true</literal>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Expressions that do not properly evaluate to true or false will
|
|
|
|
generate a warning and be treated as false.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
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
|
|
|
|
(<command>\if</command>, <command>\elif</command>,
|
|
|
|
<command>\else</command>, <command>\endif</command>) 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.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
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
|
|
|
|
<command>\include</command>-ed file before all local
|
|
|
|
<command>\if</command>-blocks have been closed,
|
2017-10-09 03:44:17 +02:00
|
|
|
then <application>psql</application> will raise an error.
|
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The control
structure feature per se is complete, but the boolean expressions
understood by \if and \elif are pretty primitive; basically, after
variable substitution and backtick expansion, the result has to be
"true" or "false" or one of the other standard spellings of a boolean
value. But that's enough for many purposes, since you can always
do the heavy lifting on the server side; and we can extend it later.
Along the way, pay down some of the technical debt that had built up
around psql/command.c:
* Refactor exec_command() into a function per command, instead of
being a 1500-line monstrosity. This makes the file noticeably longer
because of repetitive function header/trailer overhead, but it seems
much more readable.
* Teach psql_get_variable() and psqlscanslash.l to suppress variable
substitution and backtick expansion on the basis of the conditional
stack state, thereby allowing removal of the OT_NO_EVAL kluge.
* Fix the no-doubt-once-expedient hack of sometimes silently substituting
mainloop.c's previous_buf for query_buf when calling HandleSlashCmds.
(It's a bit remarkable that commands like \r worked at all with that.)
Recall of a previous query is now done explicitly in the slash commands
where that should happen.
Corey Huinker, reviewed by Fabien Coelho, further hacking by me
Discussion: https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com
2017-03-30 18:59:11 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Here is an example:
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
-- check for the existence of two separate records in the database and store
|
|
|
|
-- the results in separate psql variables
|
|
|
|
SELECT
|
|
|
|
EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,
|
|
|
|
EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee
|
|
|
|
\gset
|
|
|
|
\if :is_customer
|
|
|
|
SELECT * FROM customer WHERE customer_id = 123;
|
|
|
|
\elif :is_employee
|
|
|
|
\echo 'is not a customer but is an employee'
|
|
|
|
SELECT * FROM employee WHERE employee_id = 456;
|
|
|
|
\else
|
|
|
|
\if yes
|
|
|
|
\echo 'not a customer or employee'
|
|
|
|
\else
|
|
|
|
\echo 'this will never print'
|
|
|
|
\endif
|
|
|
|
\endif
|
|
|
|
</programlisting>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-include-relative">
|
2017-06-14 17:09:33 +02:00
|
|
|
<term><literal>\ir</literal> or <literal>\include_relative</literal> <replaceable class="parameter">filename</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>\ir</literal> command is similar to <literal>\i</literal>, but resolves
|
2017-06-14 17:09:33 +02:00
|
|
|
relative file names differently. When executing in interactive mode,
|
|
|
|
the two commands behave identically. However, when invoked from a
|
|
|
|
script, <literal>\ir</literal> interprets file names relative to the
|
|
|
|
directory in which the script is located, rather than the current
|
|
|
|
working directory.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-list">
|
2017-10-20 03:16:39 +02:00
|
|
|
<term><literal>\l[+]</literal> or <literal>\list[+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2013-03-04 04:17:08 +01:00
|
|
|
List the databases in the server and show their names, owners,
|
|
|
|
character set encodings, and access privileges.
|
|
|
|
If <replaceable class="parameter">pattern</replaceable> is specified,
|
|
|
|
only databases whose names match the pattern are listed.
|
2008-03-30 20:10:20 +02:00
|
|
|
If <literal>+</literal> 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.)
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-lo-export">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\lo_export <replaceable class="parameter">loid</replaceable> <replaceable class="parameter">filename</replaceable></literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Reads the large object with <acronym>OID</acronym> <replaceable
|
|
|
|
class="parameter">loid</replaceable> from the database and
|
|
|
|
writes it to <replaceable
|
|
|
|
class="parameter">filename</replaceable>. Note that this is
|
|
|
|
subtly different from the server function
|
|
|
|
<function>lo_export</function>, which acts with the permissions
|
|
|
|
of the user that the database server runs as and on the server's
|
|
|
|
file system.
|
|
|
|
</para>
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
Use <command>\lo_list</command> to find out the large object's
|
|
|
|
<acronym>OID</acronym>.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-lo-import">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\lo_import <replaceable class="parameter">filename</replaceable> [ <replaceable class="parameter">comment</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Stores the file into a <productname>PostgreSQL</productname>
|
|
|
|
large object. Optionally, it associates the given
|
|
|
|
comment with the object. Example:
|
2002-07-28 17:22:21 +02:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
foo=> <userinput>\lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'</userinput>
|
2002-07-28 17:22:21 +02:00
|
|
|
lo_import 152801
|
|
|
|
</programlisting>
|
2007-01-20 17:57:31 +01:00
|
|
|
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
|
|
|
|
<command>\lo_list</command> command.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
|
|
|
Note that this command is subtly different from the server-side
|
|
|
|
<function>lo_import</function> because it acts as the local user
|
|
|
|
on the local file system, rather than the server's user and file
|
|
|
|
system.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-lo-list">
|
2022-01-06 19:09:05 +01:00
|
|
|
<term><literal>\lo_list[+]</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Shows a list of all <productname>PostgreSQL</productname>
|
|
|
|
large objects currently stored in the database,
|
|
|
|
along with any comments provided for them.
|
2022-01-06 19:09:05 +01:00
|
|
|
If <literal>+</literal> is appended to the command name,
|
|
|
|
each large object is listed with its associated permissions,
|
|
|
|
if any.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-lo-unlink">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\lo_unlink <replaceable class="parameter">loid</replaceable></literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Deletes the large object with <acronym>OID</acronym>
|
|
|
|
<replaceable class="parameter">loid</replaceable> from the
|
|
|
|
database.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
Use <command>\lo_list</command> to find out the large object's
|
|
|
|
<acronym>OID</acronym>.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-out">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\o</literal> or <literal>\out [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
|
|
|
|
<term><literal>\o</literal> or <literal>\out [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2014-12-29 20:20:54 +01:00
|
|
|
Arranges to save future query results to the file <replaceable
|
|
|
|
class="parameter">filename</replaceable> or pipe future results
|
|
|
|
to the shell command <replaceable
|
|
|
|
class="parameter">command</replaceable>. If no argument is
|
|
|
|
specified, the query output is reset to the standard output.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
2017-04-03 01:01:53 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If the argument begins with <literal>|</literal>, then the entire remainder
|
2017-04-03 01:01:53 +02:00
|
|
|
of the line is taken to be
|
|
|
|
the <replaceable class="parameter">command</replaceable> 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.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<quote>Query results</quote> includes all tables, command
|
2004-06-18 08:14:31 +02:00
|
|
|
responses, and notices obtained from the database server, as
|
|
|
|
well as output of various backslash commands that query the
|
2017-04-03 01:01:53 +02:00
|
|
|
database (such as <command>\d</command>); but not error
|
2004-06-18 08:14:31 +02:00
|
|
|
messages.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
To intersperse text output in between query results, use
|
|
|
|
<command>\qecho</command>.
|
|
|
|
</para>
|
|
|
|
</tip>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
2002-03-05 01:01:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-print">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\p</literal> or <literal>\print</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-07-28 17:22:21 +02:00
|
|
|
Print the current query buffer to the standard output.
|
2017-04-03 00:26:37 +02:00
|
|
|
If the current query buffer is empty, the most recently executed query
|
|
|
|
is printed instead.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-password">
|
2005-12-20 01:51:45 +01:00
|
|
|
<term><literal>\password [ <replaceable class="parameter">username</replaceable> ]</literal></term>
|
2005-12-18 03:17:16 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-12-20 01:51:45 +01:00
|
|
|
Changes the password of the specified user (by default, the current
|
|
|
|
user). This command prompts for the new password, encrypts it, and
|
2017-10-09 03:44:17 +02:00
|
|
|
sends it to the server as an <command>ALTER ROLE</command> command. This
|
2005-12-20 01:51:45 +01:00
|
|
|
makes sure that the new password does not appear in cleartext in the
|
|
|
|
command history, the server log, or elsewhere.
|
2005-12-18 03:17:16 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-prompt">
|
2007-02-23 19:20:59 +01:00
|
|
|
<term><literal>\prompt [ <replaceable class="parameter">text</replaceable> ] <replaceable class="parameter">name</replaceable></literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-08-26 19:52:23 +02:00
|
|
|
Prompts the user to supply text, which is assigned to the variable
|
2017-10-09 03:44:17 +02:00
|
|
|
<replaceable class="parameter">name</replaceable>.
|
2011-08-26 19:52:23 +02:00
|
|
|
An optional prompt string, <replaceable
|
2017-10-09 03:44:17 +02:00
|
|
|
class="parameter">text</replaceable>, can be specified. (For multiword
|
2011-08-26 19:52:23 +02:00
|
|
|
prompts, surround the text with single quotes.)
|
2007-02-23 19:20:59 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
By default, <literal>\prompt</literal> uses the terminal for input and
|
|
|
|
output. However, if the <option>-f</option> command line switch was
|
|
|
|
used, <literal>\prompt</literal> uses standard input and standard output.
|
2007-02-23 19:20:59 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset">
|
2014-07-24 14:06:54 +02:00
|
|
|
<term><literal>\pset [ <replaceable class="parameter">option</replaceable> [ <replaceable class="parameter">value</replaceable> ] ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
This command sets options affecting the output of query result tables.
|
|
|
|
<replaceable class="parameter">option</replaceable>
|
|
|
|
indicates which option is to be set. The semantics of
|
|
|
|
<replaceable class="parameter">value</replaceable> vary depending
|
|
|
|
on the selected option. For some options, omitting <replaceable
|
|
|
|
class="parameter">value</replaceable> causes the option to be toggled
|
|
|
|
or unset, as described under the particular option. If no such
|
|
|
|
behavior is mentioned, then omitting
|
|
|
|
<replaceable class="parameter">value</replaceable> just results in
|
|
|
|
the current setting being displayed.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
2014-07-24 14:06:54 +02:00
|
|
|
<para>
|
|
|
|
<command>\pset</command> without any arguments displays the current status
|
|
|
|
of all printing options.
|
|
|
|
</para>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
|
|
|
Adjustable printing options are:
|
|
|
|
<variablelist>
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-border">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>border</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The <replaceable class="parameter">value</replaceable> must be a
|
|
|
|
number. In general, the higher
|
|
|
|
the number the more borders and lines the tables will have,
|
2015-11-03 17:49:21 +01:00
|
|
|
but details depend on the particular format.
|
|
|
|
In <acronym>HTML</acronym> format, this will translate directly
|
|
|
|
into the <literal>border=...</literal> 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 <literal>border = 2</literal>.
|
|
|
|
The <literal>latex</literal> and <literal>latex-longtable</literal>
|
|
|
|
formats additionally allow a value of 3 to add dividing lines
|
|
|
|
between data rows.
|
2011-05-22 14:13:17 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-columns">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>columns</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Sets the target width for the <literal>wrapped</literal> format, and also
|
2011-05-22 14:13:17 +02:00
|
|
|
the width limit for determining whether output is wide enough to
|
2011-11-12 16:03:10 +01:00
|
|
|
require the pager or switch to the vertical display in expanded auto
|
|
|
|
mode.
|
2011-05-22 14:13:17 +02:00
|
|
|
Zero (the default) causes the target width to be controlled by the
|
2017-10-09 03:44:17 +02:00
|
|
|
environment variable <envar>COLUMNS</envar>, or the detected screen width
|
|
|
|
if <envar>COLUMNS</envar> is not set.
|
|
|
|
In addition, if <literal>columns</literal> is zero then the
|
|
|
|
<literal>wrapped</literal> format only affects screen output.
|
|
|
|
If <literal>columns</literal> is nonzero then file and pipe output is
|
2011-05-22 14:13:17 +02:00
|
|
|
wrapped to that width as well.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-csv-fieldsep">
|
2018-11-26 21:18:55 +01:00
|
|
|
<term><literal>csv_fieldsep</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies the field separator to be used in
|
|
|
|
<acronym>CSV</acronym> output format. If the separator character
|
|
|
|
appears in a field's value, that field is output within double
|
|
|
|
quotes, following standard <acronym>CSV</acronym> rules.
|
|
|
|
The default is a comma.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-expanded">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>expanded</literal> (or <literal>x</literal>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-11-12 16:03:10 +01:00
|
|
|
If <replaceable class="parameter">value</replaceable> is specified it
|
|
|
|
must be either <literal>on</literal> or <literal>off</literal>, which
|
|
|
|
will enable or disable expanded mode, or <literal>auto</literal>.
|
|
|
|
If <replaceable class="parameter">value</replaceable> 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't fit on the screen in the
|
|
|
|
normal <quote>horizontal</quote> mode. In the auto setting, the
|
2016-03-11 14:04:01 +01:00
|
|
|
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
|
2011-11-12 16:03:10 +01:00
|
|
|
effective in the aligned and wrapped formats. In other formats, it
|
|
|
|
always behaves as if the expanded mode is off.
|
2011-05-22 14:13:17 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2022-07-25 20:24:50 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-fieldsep">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>fieldsep</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies the field separator to be used in unaligned output
|
2018-11-26 21:18:55 +01:00
|
|
|
format. That way one can create, for example, tab-separated
|
|
|
|
output, which other programs might prefer. To
|
2011-05-22 14:13:17 +02:00
|
|
|
set a tab as field separator, type <literal>\pset fieldsep
|
|
|
|
'\t'</literal>. The default field separator is
|
|
|
|
<literal>'|'</literal> (a vertical bar).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-fieldsep-zero">
|
2012-02-09 19:15:48 +01:00
|
|
|
<term><literal>fieldsep_zero</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the field separator to use in unaligned output format to a zero
|
|
|
|
byte.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-footer">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>footer</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If <replaceable class="parameter">value</replaceable> is specified
|
|
|
|
it must be either <literal>on</literal> or <literal>off</literal>
|
|
|
|
which will enable or disable display of the table footer
|
2017-10-09 03:44:17 +02:00
|
|
|
(the <literal>(<replaceable>n</replaceable> rows)</literal> count).
|
2011-05-22 14:13:17 +02:00
|
|
|
If <replaceable class="parameter">value</replaceable> is omitted the
|
|
|
|
command toggles footer display on or off.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-format">
|
2004-06-18 08:14:31 +02:00
|
|
|
<term><literal>format</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2018-11-06 07:04:40 +01:00
|
|
|
Sets the output format to one of <literal>aligned</literal>,
|
2018-11-26 21:18:55 +01:00
|
|
|
<literal>asciidoc</literal>,
|
|
|
|
<literal>csv</literal>,
|
|
|
|
<literal>html</literal>,
|
|
|
|
<literal>latex</literal>,
|
2018-11-06 07:04:40 +01:00
|
|
|
<literal>latex-longtable</literal>, <literal>troff-ms</literal>,
|
|
|
|
<literal>unaligned</literal>, or <literal>wrapped</literal>.
|
2018-11-14 22:29:57 +01:00
|
|
|
Unique abbreviations are allowed.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
2018-11-26 21:18:55 +01:00
|
|
|
<para><literal>aligned</literal> format is the standard,
|
|
|
|
human-readable, nicely formatted text output; this is the default.
|
|
|
|
</para>
|
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
<para><literal>unaligned</literal> format writes all columns of a row on one
|
2004-06-18 08:14:31 +02:00
|
|
|
line, separated by the currently active field separator. This
|
2009-11-22 23:06:30 +01:00
|
|
|
is useful for creating output that might be intended to be read
|
2018-11-26 21:18:55 +01:00
|
|
|
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's value;
|
|
|
|
so <acronym>CSV</acronym> format may be better suited for such
|
|
|
|
purposes.
|
2009-11-22 23:06:30 +01:00
|
|
|
</para>
|
|
|
|
|
2018-11-26 21:18:55 +01:00
|
|
|
<para><literal>csv</literal> format
|
|
|
|
<indexterm>
|
|
|
|
<primary>CSV (Comma-Separated Values) format</primary>
|
|
|
|
<secondary>in psql</secondary>
|
|
|
|
</indexterm>
|
|
|
|
writes column values separated by commas, applying the quoting
|
|
|
|
rules described in
|
2024-04-10 13:53:25 +02:00
|
|
|
<ulink url="https://datatracker.ietf.org/doc/html/rfc4180">RFC 4180</ulink>.
|
2018-11-26 21:18:55 +01:00
|
|
|
This output is compatible with the CSV format of the server's
|
|
|
|
<command>COPY</command> command.
|
|
|
|
A header line with column names is generated unless
|
|
|
|
the <literal>tuples_only</literal> parameter is
|
|
|
|
<literal>on</literal>. Titles and footers are not printed.
|
|
|
|
Each row is terminated by the system-dependent end-of-line character,
|
|
|
|
which is typically a single newline (<literal>\n</literal>) for
|
|
|
|
Unix-like systems or a carriage return and newline sequence
|
|
|
|
(<literal>\r\n</literal>) for Microsoft Windows.
|
|
|
|
Field separator characters other than comma can be selected with
|
|
|
|
<command>\pset csv_fieldsep</command>.
|
2008-05-08 19:04:26 +02:00
|
|
|
</para>
|
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
<para><literal>wrapped</literal> format is like <literal>aligned</literal> but wraps
|
2009-11-22 23:06:30 +01:00
|
|
|
wide data values across lines to make the output fit in the target
|
|
|
|
column width. The target width is determined as described under
|
2017-10-09 03:44:17 +02:00
|
|
|
the <literal>columns</literal> option. Note that <application>psql</application> will
|
2009-11-22 23:06:30 +01:00
|
|
|
not attempt to wrap column header titles; therefore,
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>wrapped</literal> format behaves the same as <literal>aligned</literal>
|
2009-11-22 23:06:30 +01:00
|
|
|
if the total width needed for column headers exceeds the target.
|
2008-05-08 19:04:26 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2018-11-06 07:04:40 +01:00
|
|
|
The <literal>asciidoc</literal>, <literal>html</literal>,
|
|
|
|
<literal>latex</literal>, <literal>latex-longtable</literal>, and
|
|
|
|
<literal>troff-ms</literal> formats put out tables that are intended
|
|
|
|
to be included in documents using the respective mark-up
|
2013-01-17 17:39:38 +01:00
|
|
|
language. They are not complete documents! This might not be
|
|
|
|
necessary in <acronym>HTML</acronym>, but in
|
|
|
|
<application>LaTeX</application> you must have a complete
|
2018-11-26 21:18:55 +01:00
|
|
|
document wrapper.
|
|
|
|
The <literal>latex</literal> format
|
|
|
|
uses <application>LaTeX</application>'s <literal>tabular</literal>
|
|
|
|
environment.
|
|
|
|
The <literal>latex-longtable</literal> format
|
|
|
|
requires the <application>LaTeX</application>
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>longtable</literal> and <literal>booktabs</literal> packages.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-linestyle">
|
2009-10-13 23:04:01 +02:00
|
|
|
<term><literal>linestyle</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the border line drawing style to one
|
2015-12-03 16:24:16 +01:00
|
|
|
of <literal>ascii</literal>, <literal>old-ascii</literal>,
|
2009-11-22 06:20:41 +01:00
|
|
|
or <literal>unicode</literal>.
|
2009-10-13 23:04:01 +02:00
|
|
|
Unique abbreviations are allowed. (That would mean one
|
|
|
|
letter is enough.)
|
2017-10-09 03:44:17 +02:00
|
|
|
The default setting is <literal>ascii</literal>.
|
|
|
|
This option only affects the <literal>aligned</literal> and
|
|
|
|
<literal>wrapped</literal> output formats.
|
2009-10-13 23:04:01 +02:00
|
|
|
</para>
|
|
|
|
|
2011-08-07 09:49:45 +02:00
|
|
|
<para><literal>ascii</literal> style uses plain <acronym>ASCII</acronym>
|
2009-11-22 06:20:41 +01:00
|
|
|
characters. Newlines in data are shown using
|
|
|
|
a <literal>+</literal> symbol in the right-hand margin.
|
2009-11-22 23:06:30 +01:00
|
|
|
When the <literal>wrapped</literal> format wraps data from
|
|
|
|
one line to the next without a newline character, a dot
|
2017-10-09 03:44:17 +02:00
|
|
|
(<literal>.</literal>) is shown in the right-hand margin of the first line,
|
2009-11-22 23:06:30 +01:00
|
|
|
and again in the left-hand margin of the following line.
|
2009-10-13 23:04:01 +02:00
|
|
|
</para>
|
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
<para><literal>old-ascii</literal> style uses plain <acronym>ASCII</acronym>
|
2009-11-22 06:20:41 +01:00
|
|
|
characters, using the formatting style used
|
|
|
|
in <productname>PostgreSQL</productname> 8.4 and earlier.
|
|
|
|
Newlines in data are shown using a <literal>:</literal>
|
|
|
|
symbol in place of the left-hand column separator.
|
2009-11-22 23:06:30 +01:00
|
|
|
When the data is wrapped from one line
|
2017-10-09 03:44:17 +02:00
|
|
|
to the next without a newline character, a <literal>;</literal>
|
2009-11-22 06:20:41 +01:00
|
|
|
symbol is used in place of the left-hand column separator.
|
|
|
|
</para>
|
|
|
|
|
2011-08-07 09:49:45 +02:00
|
|
|
<para><literal>unicode</literal> style uses Unicode box-drawing characters.
|
2009-11-22 06:20:41 +01:00
|
|
|
Newlines in data are shown using a carriage return symbol
|
2009-11-22 23:06:30 +01:00
|
|
|
in the right-hand margin. When the data is wrapped from one line
|
2009-11-22 06:20:41 +01:00
|
|
|
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.
|
2009-10-13 23:04:01 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When the <literal>border</literal> setting is greater than zero,
|
2015-11-03 17:49:21 +01:00
|
|
|
the <literal>linestyle</literal> option also determines the
|
|
|
|
characters with which the border lines are drawn.
|
2009-10-13 23:04:01 +02:00
|
|
|
Plain <acronym>ASCII</acronym> characters work everywhere, but
|
|
|
|
Unicode characters look nicer on displays that recognize them.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-null">
|
2004-06-18 08:14:31 +02:00
|
|
|
<term><literal>null</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
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 <literal>\pset null
|
2004-06-18 08:14:31 +02:00
|
|
|
'(null)'</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-numericlocale">
|
2005-07-18 22:57:53 +02:00
|
|
|
<term><literal>numericlocale</literal></term>
|
2005-07-10 05:46:13 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
If <replaceable class="parameter">value</replaceable> is specified
|
|
|
|
it must be either <literal>on</literal> or <literal>off</literal>
|
|
|
|
which will enable or disable display of a locale-specific character
|
|
|
|
to separate groups of digits to the left of the decimal marker.
|
|
|
|
If <replaceable class="parameter">value</replaceable> is omitted the
|
|
|
|
command toggles between regular and locale-specific numeric output.
|
2005-07-10 05:46:13 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-pager">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>pager</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Controls use of a pager program for query and <application>psql</application>
|
2023-05-12 22:11:14 +02:00
|
|
|
help output.
|
|
|
|
When the <literal>pager</literal> option is <literal>off</literal>, the pager
|
|
|
|
program is not used. When the <literal>pager</literal> option is
|
|
|
|
<literal>on</literal>, the pager is used when appropriate, i.e., when the
|
|
|
|
output is to a terminal and will not fit on the screen.
|
|
|
|
The <literal>pager</literal> option can also be set to <literal>always</literal>,
|
|
|
|
which causes the pager to be used for all terminal output regardless
|
|
|
|
of whether it fits on the screen. <literal>\pset pager</literal>
|
|
|
|
without a <replaceable class="parameter">value</replaceable>
|
|
|
|
toggles pager use on and off.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If the environment variable <envar>PSQL_PAGER</envar>
|
|
|
|
or <envar>PAGER</envar> is set, output to be paged is piped to the
|
2017-09-05 18:02:06 +02:00
|
|
|
specified program. Otherwise a platform-dependent default program
|
|
|
|
(such as <filename>more</filename>) is used.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
2021-07-13 01:13:48 +02:00
|
|
|
<para>
|
|
|
|
When using the <literal>\watch</literal> command to execute a query
|
|
|
|
repeatedly, the environment variable <envar>PSQL_WATCH_PAGER</envar>
|
|
|
|
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
|
|
|
|
<application>psql</application>'s output format (such as
|
|
|
|
<filename>pspg --stream</filename>).
|
|
|
|
</para>
|
2004-06-18 08:14:31 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-pager-min-lines">
|
2015-03-28 16:07:41 +01:00
|
|
|
<term><literal>pager_min_lines</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If <literal>pager_min_lines</literal> is set to a number greater than the
|
2015-03-28 16:07:41 +01:00
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-recordsep">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>recordsep</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-05-22 14:13:17 +02:00
|
|
|
Specifies the record (line) separator to use in unaligned
|
|
|
|
output format. The default is a newline character.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-recordsep-zero">
|
2012-02-09 19:15:48 +01:00
|
|
|
<term><literal>recordsep_zero</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the record separator to use in unaligned output format to a zero
|
|
|
|
byte.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-tableattr">
|
2009-11-22 23:06:30 +01:00
|
|
|
<term><literal>tableattr</literal> (or <literal>T</literal>)</term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2013-01-17 17:39:38 +01:00
|
|
|
In <acronym>HTML</acronym> format, this specifies attributes
|
|
|
|
to be placed inside the <sgmltag>table</sgmltag> tag. This
|
2004-06-18 08:14:31 +02:00
|
|
|
could for example be <literal>cellpadding</literal> or
|
|
|
|
<literal>bgcolor</literal>. Note that you probably don't want
|
|
|
|
to specify <literal>border</literal> here, as that is already
|
|
|
|
taken care of by <literal>\pset border</literal>.
|
2009-11-22 23:06:30 +01:00
|
|
|
If no
|
|
|
|
<replaceable class="parameter">value</replaceable> is given,
|
|
|
|
the table attributes are unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2013-01-17 17:39:38 +01:00
|
|
|
<para>
|
|
|
|
In <literal>latex-longtable</literal> format, this controls
|
|
|
|
the proportional width of each column containing a left-aligned
|
2013-01-18 14:30:31 +01:00
|
|
|
data type. It is specified as a whitespace-separated list of values,
|
2020-09-01 00:33:37 +02:00
|
|
|
e.g., <literal>'0.2 0.2 0.6'</literal>. Unspecified output columns
|
2013-01-17 17:39:38 +01:00
|
|
|
use the last specified value.
|
|
|
|
</para>
|
2004-06-18 08:14:31 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-title">
|
2015-10-06 02:56:38 +02:00
|
|
|
<term><literal>title</literal> (or <literal>C</literal>)</term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-05-22 14:13:17 +02:00
|
|
|
Sets the table title for any subsequently printed tables. This
|
|
|
|
can be used to give your output descriptive tags. If no
|
|
|
|
<replaceable class="parameter">value</replaceable> is given,
|
|
|
|
the title is unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2011-05-22 14:13:17 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-tuples-only">
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>tuples_only</literal> (or <literal>t</literal>)</term>
|
|
|
|
<listitem>
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
2011-05-22 14:13:17 +02:00
|
|
|
If <replaceable class="parameter">value</replaceable> is specified
|
|
|
|
it must be either <literal>on</literal> or <literal>off</literal>
|
|
|
|
which will enable or disable tuples-only mode.
|
|
|
|
If <replaceable class="parameter">value</replaceable> 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.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2014-09-12 18:04:37 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-unicode-border-linestyle">
|
2015-11-03 17:49:21 +01:00
|
|
|
<term><literal>unicode_border_linestyle</literal></term>
|
2014-09-12 18:04:37 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-11-03 17:49:21 +01:00
|
|
|
Sets the border drawing style for the <literal>unicode</literal>
|
|
|
|
line style to one of <literal>single</literal>
|
|
|
|
or <literal>double</literal>.
|
2014-09-12 18:04:37 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-unicode-column-linestyle">
|
2015-11-03 17:49:21 +01:00
|
|
|
<term><literal>unicode_column_linestyle</literal></term>
|
2014-09-12 18:04:37 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-11-03 17:49:21 +01:00
|
|
|
Sets the column drawing style for the <literal>unicode</literal>
|
|
|
|
line style to one of <literal>single</literal>
|
|
|
|
or <literal>double</literal>.
|
2014-09-12 18:04:37 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-pset-unicode-header-linestyle">
|
2015-11-03 17:49:21 +01:00
|
|
|
<term><literal>unicode_header_linestyle</literal></term>
|
2014-09-12 18:04:37 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-11-03 17:49:21 +01:00
|
|
|
Sets the header drawing style for the <literal>unicode</literal>
|
|
|
|
line style to one of <literal>single</literal>
|
|
|
|
or <literal>double</literal>.
|
2014-09-12 18:04:37 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2023-06-13 15:00:52 +02:00
|
|
|
|
|
|
|
<varlistentry id="app-psql-meta-command-pset-xheader-width">
|
|
|
|
<term><literal>xheader_width</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the maximum width of the header for expanded output to one of
|
|
|
|
<literal>full</literal> (the default value),
|
|
|
|
<literal>column</literal>, <literal>page</literal>, or an
|
|
|
|
<replaceable class="parameter">integer value</replaceable>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<literal>full</literal>: the expanded header is not truncated,
|
|
|
|
and will be as wide as the widest output line.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<literal>column</literal>: truncate the header line to the
|
|
|
|
width of the first column.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<literal>page</literal>: truncate the header line to the terminal
|
|
|
|
width.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<replaceable class="parameter">integer value</replaceable>: specify
|
|
|
|
the exact maximum width of the header line.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
Illustrations of how these different formats look can be seen in
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<xref linkend="app-psql-examples"/>, below.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
There are various shortcut commands for <command>\pset</command>. See
|
2017-07-05 03:10:08 +02:00
|
|
|
<command>\a</command>, <command>\C</command>, <command>\f</command>,
|
|
|
|
<command>\H</command>, <command>\t</command>, <command>\T</command>,
|
|
|
|
and <command>\x</command>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-quit">
|
2011-10-12 19:59:30 +02:00
|
|
|
<term><literal>\q</literal> or <literal>\quit</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Quits the <application>psql</application> program.
|
2011-10-12 19:59:30 +02:00
|
|
|
In a script file, only execution of that script is terminated.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-qecho">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\qecho <replaceable class="parameter">text</replaceable> [ ... ] </literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
This command is identical to <command>\echo</command> except
|
2005-01-04 04:58:16 +01:00
|
|
|
that the output will be written to the query output channel, as
|
2004-06-18 08:14:31 +02:00
|
|
|
set by <command>\o</command>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-reset">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\r</literal> or <literal>\reset</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Resets (clears) the query buffer.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-s">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\s [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
Fix psql \s to work with recent libedit, and add pager support.
psql's \s (print command history) doesn't work at all with recent libedit
versions when printing to the terminal, because libedit tries to do an
fchmod() on the target file which will fail if the target is /dev/tty.
(We'd already noted this in the context of the target being /dev/null.)
Even before that, it didn't work pleasantly, because libedit likes to
encode the command history file (to ensure successful reloading), which
renders it nigh unreadable, not to mention significantly different-looking
depending on exactly which libedit version you have. So let's forget using
write_history() for this purpose, and instead print the data ourselves,
using logic similar to that used to iterate over the history for newline
encoding/decoding purposes.
While we're at it, insert the ability to use the pager when \s is printing
to the terminal. This has been an acknowledged shortcoming of \s for many
years, so while you could argue it's not exactly a back-patchable bug fix
it still seems like a good improvement. Anyone who's seriously annoyed
at this can use "\s /dev/tty" or local equivalent to get the old behavior.
Experimentation with this showed that the history iteration logic was
actually rather broken when used with libedit. It turns out that with
libedit you have to use previous_history() not next_history() to advance
to more recent history entries. The easiest and most robust fix for this
seems to be to make a run-time test to verify which function to call.
We had not noticed this because libedit doesn't really need the newline
encoding logic: its own encoding ensures that command entries containing
newlines are reloaded correctly (unlike libreadline). So the effective
behavior with recent libedits was that only the oldest history entry got
newline-encoded or newline-decoded. However, because of yet other bugs in
history_set_pos(), some old versions of libedit allowed the existing loop
logic to reach entries besides the oldest, which means there may be libedit
~/.psql_history files out there containing encoded newlines in more than
just the oldest entry. To ensure we can reload such files, it seems
appropriate to back-patch this fix, even though that will result in some
incompatibility with older psql versions (ie, multiline history entries
written by a psql with this fix will look corrupted to a psql without it,
if its libedit is reasonably up to date).
Stepan Rutz and Tom Lane
2014-09-08 22:09:45 +02:00
|
|
|
Print <application>psql</application>'s command line history
|
|
|
|
to <replaceable class="parameter">filename</replaceable>.
|
|
|
|
If <replaceable class="parameter">filename</replaceable> is omitted,
|
|
|
|
the history is written to the standard output (using the pager if
|
|
|
|
appropriate). This command is not available
|
|
|
|
if <application>psql</application> was built
|
|
|
|
without <application>Readline</application> support.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2000-02-08 00:10:11 +01:00
|
|
|
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-set">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\set [ <replaceable class="parameter">name</replaceable> [ <replaceable class="parameter">value</replaceable> [ ... ] ] ]</literal></term>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Sets the <application>psql</application> variable <replaceable
|
2004-06-18 08:14:31 +02:00
|
|
|
class="parameter">name</replaceable> to <replaceable
|
2011-08-26 19:52:23 +02:00
|
|
|
class="parameter">value</replaceable>, or if more than one value
|
|
|
|
is given, to the concatenation of all of them. If only one
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
argument is given, the variable is set to an empty-string value. To
|
2004-06-18 08:14:31 +02:00
|
|
|
unset a variable, use the <command>\unset</command> command.
|
|
|
|
</para>
|
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
<para><command>\set</command> without any arguments displays the names and values
|
|
|
|
of all currently-set <application>psql</application> variables.
|
2011-08-26 19:52:23 +02:00
|
|
|
</para>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
2011-08-26 16:41:31 +02:00
|
|
|
Valid variable names can contain letters, digits, and
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
underscores. See <xref linkend="app-psql-variables"/> below for details.
|
2004-06-18 08:14:31 +02:00
|
|
|
Variable names are case-sensitive.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
Certain variables are special, in that they
|
|
|
|
control <application>psql</application>'s behavior or are
|
|
|
|
automatically set to reflect connection state. These variables are
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
documented in <xref linkend="app-psql-variables"/>, below.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
2011-08-26 19:52:23 +02:00
|
|
|
This command is unrelated to the <acronym>SQL</acronym>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
command <link linkend="sql-set"><command>SET</command></link>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-setenv">
|
2015-02-02 06:18:54 +01:00
|
|
|
<term><literal>\setenv <replaceable class="parameter">name</replaceable> [ <replaceable class="parameter">value</replaceable> ]</literal></term>
|
2011-12-04 17:43:38 +01:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the environment variable <replaceable
|
|
|
|
class="parameter">name</replaceable> to <replaceable
|
|
|
|
class="parameter">value</replaceable>, or if the
|
|
|
|
<replaceable class="parameter">value</replaceable> is
|
|
|
|
not supplied, unsets the environment variable. Example:
|
|
|
|
<programlisting>
|
|
|
|
testdb=> <userinput>\setenv PAGER less</userinput>
|
|
|
|
testdb=> <userinput>\setenv LESS -imx4F</userinput>
|
2012-03-28 19:37:19 +02:00
|
|
|
</programlisting></para>
|
2011-12-04 17:43:38 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-sf">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\sf[+] <replaceable class="parameter">function_description</replaceable> </literal></term>
|
2010-08-14 15:59:49 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2018-02-13 16:34:04 +01:00
|
|
|
This command fetches and shows the definition of the named function or procedure,
|
|
|
|
in the form of a <command>CREATE OR REPLACE FUNCTION</command> or
|
|
|
|
<command>CREATE OR REPLACE PROCEDURE</command> command.
|
2010-08-14 15:59:49 +02:00
|
|
|
The definition is printed to the current query output channel,
|
|
|
|
as set by <command>\o</command>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The target function can be specified by name alone, or by name
|
2017-10-09 03:44:17 +02:00
|
|
|
and arguments, for example <literal>foo(integer, text)</literal>.
|
2010-08-14 15:59:49 +02:00
|
|
|
The argument types must be given if there is more
|
|
|
|
than one function of the same name.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If <literal>+</literal> is appended to the command name, then the
|
|
|
|
output lines are numbered, with the first line of the function body
|
|
|
|
being line 1.
|
|
|
|
</para>
|
2017-04-03 01:01:53 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Unlike most other meta-commands, the entire remainder of the line is
|
2017-10-09 03:44:17 +02:00
|
|
|
always taken to be the argument(s) of <command>\sf</command>, and neither
|
2017-04-03 01:01:53 +02:00
|
|
|
variable interpolation nor backquote expansion are performed in the
|
|
|
|
arguments.
|
|
|
|
</para>
|
2010-08-14 15:59:49 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-sv">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\sv[+] <replaceable class="parameter">view_name</replaceable> </literal></term>
|
2015-07-03 21:48:18 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This command fetches and shows the definition of the named view,
|
2017-10-09 03:44:17 +02:00
|
|
|
in the form of a <command>CREATE OR REPLACE VIEW</command> command.
|
2015-07-03 21:48:18 +02:00
|
|
|
The definition is printed to the current query output channel,
|
|
|
|
as set by <command>\o</command>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If <literal>+</literal> is appended to the command name, then the
|
|
|
|
output lines are numbered from 1.
|
|
|
|
</para>
|
2017-04-03 01:01:53 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Unlike most other meta-commands, the entire remainder of the line is
|
2017-10-09 03:44:17 +02:00
|
|
|
always taken to be the argument(s) of <command>\sv</command>, and neither
|
2017-04-03 01:01:53 +02:00
|
|
|
variable interpolation nor backquote expansion are performed in the
|
|
|
|
arguments.
|
|
|
|
</para>
|
2015-07-03 21:48:18 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-t-lc">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\t</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Toggles the display of output column name headings and row count
|
|
|
|
footer. This command is equivalent to <literal>\pset
|
|
|
|
tuples_only</literal> and is provided for convenience.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-t-uc">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\T <replaceable class="parameter">table_options</replaceable></literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
Specifies attributes to be placed within the
|
|
|
|
<sgmltag>table</sgmltag> tag in <acronym>HTML</acronym>
|
|
|
|
output format. This command is equivalent to <literal>\pset
|
2002-07-28 17:22:21 +02:00
|
|
|
tableattr <replaceable
|
|
|
|
class="parameter">table_options</replaceable></literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-timing">
|
2008-06-11 12:48:17 +02:00
|
|
|
<term><literal>\timing [ <replaceable class="parameter">on</replaceable> | <replaceable class="parameter">off</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-09-03 21:29:03 +02:00
|
|
|
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.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-unset">
|
2011-08-26 19:52:23 +02:00
|
|
|
<term><literal>\unset <replaceable class="parameter">name</replaceable></literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Unsets (deletes) the <application>psql</application> variable <replaceable
|
2011-08-26 19:52:23 +02:00
|
|
|
class="parameter">name</replaceable>.
|
|
|
|
</para>
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Most variables that control <application>psql</application>'s behavior
|
2017-10-09 03:44:17 +02:00
|
|
|
cannot be unset; instead, an <literal>\unset</literal> command is interpreted
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
as setting them to their default values.
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
See <xref linkend="app-psql-variables"/> below.
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
</para>
|
2011-08-26 19:52:23 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-write">
|
2014-12-29 20:20:54 +01:00
|
|
|
<term><literal>\w</literal> or <literal>\write</literal> <replaceable class="parameter">filename</replaceable></term>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\w</literal> or <literal>\write</literal> <literal>|</literal><replaceable class="parameter">command</replaceable></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-04-03 00:26:37 +02:00
|
|
|
Writes the current query buffer to the file <replaceable
|
2014-12-29 20:20:54 +01:00
|
|
|
class="parameter">filename</replaceable> or pipes it to the shell
|
2002-07-28 17:22:21 +02:00
|
|
|
command <replaceable class="parameter">command</replaceable>.
|
2017-04-03 00:26:37 +02:00
|
|
|
If the current query buffer is empty, the most recently executed query
|
|
|
|
is written instead.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2017-04-03 01:01:53 +02:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If the argument begins with <literal>|</literal>, then the entire remainder
|
2017-04-03 01:01:53 +02:00
|
|
|
of the line is taken to be
|
|
|
|
the <replaceable class="parameter">command</replaceable> 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.
|
|
|
|
</para>
|
2013-04-05 01:56:33 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-warn">
|
2019-07-05 18:32:36 +02:00
|
|
|
<term><literal>\warn <replaceable class="parameter">text</replaceable> [ ... ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This command is identical to <command>\echo</command> except
|
|
|
|
that the output will be written to <application>psql</application>'s
|
|
|
|
standard error channel, rather than standard output.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-watch">
|
2023-08-29 11:30:11 +02:00
|
|
|
<term><literal>\watch [ i[nterval]=<replaceable class="parameter">seconds</replaceable> ] [ c[ount]=<replaceable class="parameter">times</replaceable> ] [ m[in_rows]=<replaceable class="parameter">rows</replaceable> ] [ <replaceable class="parameter">seconds</replaceable> ]</literal></term>
|
2013-04-05 01:56:33 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Repeatedly execute the current query buffer (as <literal>\g</literal> does)
|
2023-04-06 19:18:14 +02:00
|
|
|
until interrupted, or the query fails, or the execution count limit
|
2023-08-29 11:30:11 +02:00
|
|
|
(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.
|
|
|
|
For backwards compatibility,
|
2023-04-06 19:18:14 +02:00
|
|
|
<replaceable class="parameter">seconds</replaceable> can be specified
|
|
|
|
with or without an <literal>interval=</literal> prefix.
|
|
|
|
Each query result is
|
2017-10-09 03:44:17 +02:00
|
|
|
displayed with a header that includes the <literal>\pset title</literal>
|
2016-03-21 23:18:13 +01:00
|
|
|
string (if any), the time as of query start, and the delay interval.
|
2013-04-05 01:56:33 +02:00
|
|
|
</para>
|
2017-04-03 00:26:37 +02:00
|
|
|
<para>
|
|
|
|
If the current query buffer is empty, the most recently sent query
|
|
|
|
is re-executed instead.
|
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-x">
|
2011-11-12 16:03:10 +01:00
|
|
|
<term><literal>\x [ <replaceable class="parameter">on</replaceable> | <replaceable class="parameter">off</replaceable> | <replaceable class="parameter">auto</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-11-12 16:03:10 +01:00
|
|
|
Sets or toggles expanded table formatting mode. As such it is equivalent to
|
2004-06-18 08:14:31 +02:00
|
|
|
<literal>\pset expanded</literal>.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-z">
|
2023-01-07 12:09:26 +01:00
|
|
|
<term><literal>\z[S] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists tables, views and sequences with their
|
2003-03-24 15:32:51 +01:00
|
|
|
associated access privileges.
|
2004-06-18 08:14:31 +02:00
|
|
|
If a <replaceable class="parameter">pattern</replaceable> is
|
2009-12-25 00:36:39 +01:00
|
|
|
specified, only tables, views and sequences whose names match the
|
2023-01-07 12:09:26 +01:00
|
|
|
pattern are listed. By default only user-created objects are shown;
|
|
|
|
supply a pattern or the <literal>S</literal> modifier to include
|
|
|
|
system objects.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
|
|
|
This is an alias for <command>\dp</command> (<quote>display
|
|
|
|
privileges</quote>).
|
2002-08-10 05:56:24 +02:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2000-03-01 22:10:05 +01:00
|
|
|
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-exclamation-mark">
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\! [ <replaceable class="parameter">command</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
With no argument, escapes to a sub-shell; <application>psql</application>
|
2017-04-03 01:01:53 +02:00
|
|
|
resumes when the sub-shell exits. With an argument, executes the
|
|
|
|
shell command <replaceable class="parameter">command</replaceable>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Unlike most other meta-commands, the entire remainder of the line is
|
2017-10-09 03:44:17 +02:00
|
|
|
always taken to be the argument(s) of <command>\!</command>, and neither
|
2017-04-03 01:01:53 +02:00
|
|
|
variable interpolation nor backquote expansion are performed in the
|
|
|
|
arguments. The rest of the line is simply passed literally to the
|
|
|
|
shell.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-question-mark">
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><literal>\? [ <replaceable class="parameter">topic</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
Add new psql help topics, accessible to both --help and \?.
Add --help=<topic> for the commandline, and \? <topic> as a backslash
command, to show more help than the invocations without parameters
do. "commands", "variables" and "options" currently exist as help
topics describing, respectively, backslash commands, psql variables,
and commandline switches. Without parameters the help commands show
their previous topic.
Some further wordsmithing or extending of the added help content might
be needed; but there seems little benefit delaying the overall feature
further.
Author: Pavel Stehule, editorialized by many
Reviewed-By: Andres Freund, Petr Jelinek, Fujii Masao, MauMau, Abhijit
Menon-Sen and Erik Rijkers.
Discussion: CAFj8pRDVGuC-nXBfe2CK8vpyzd2Dsr9GVpbrATAnZO=2YQ0s2Q@mail.gmail.com,
CAFj8pRA54AbTv2RXDTRxiAd8hy8wxmoVLqhJDRCwEnhdd7OUkw@mail.gmail.com
2014-09-09 22:19:14 +02:00
|
|
|
Shows help information. The optional
|
2017-10-09 03:44:17 +02:00
|
|
|
<replaceable class="parameter">topic</replaceable> parameter
|
|
|
|
(defaulting to <literal>commands</literal>) selects which part of <application>psql</application> is
|
|
|
|
explained: <literal>commands</literal> describes <application>psql</application>'s
|
|
|
|
backslash commands; <literal>options</literal> describes the command-line
|
|
|
|
options that can be passed to <application>psql</application>;
|
|
|
|
and <literal>variables</literal> shows help about <application>psql</application> configuration
|
Add new psql help topics, accessible to both --help and \?.
Add --help=<topic> for the commandline, and \? <topic> as a backslash
command, to show more help than the invocations without parameters
do. "commands", "variables" and "options" currently exist as help
topics describing, respectively, backslash commands, psql variables,
and commandline switches. Without parameters the help commands show
their previous topic.
Some further wordsmithing or extending of the added help content might
be needed; but there seems little benefit delaying the overall feature
further.
Author: Pavel Stehule, editorialized by many
Reviewed-By: Andres Freund, Petr Jelinek, Fujii Masao, MauMau, Abhijit
Menon-Sen and Erik Rijkers.
Discussion: CAFj8pRDVGuC-nXBfe2CK8vpyzd2Dsr9GVpbrATAnZO=2YQ0s2Q@mail.gmail.com,
CAFj8pRA54AbTv2RXDTRxiAd8hy8wxmoVLqhJDRCwEnhdd7OUkw@mail.gmail.com
2014-09-09 22:19:14 +02:00
|
|
|
variables.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2017-09-07 20:04:41 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-meta-command-semicolon">
|
2017-09-07 20:04:41 +02:00
|
|
|
<term><literal>\;</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-06-11 03:38:04 +02:00
|
|
|
Normally, <application>psql</application> will dispatch an SQL command to the
|
2017-09-07 20:04:41 +02:00
|
|
|
server as soon as it reaches the command-ending semicolon, even if
|
|
|
|
more input remains on the current line. Thus for example entering
|
|
|
|
<programlisting>
|
|
|
|
select 1; select 2; select 3;
|
|
|
|
</programlisting>
|
|
|
|
will result in the three SQL commands being individually sent to
|
|
|
|
the server, with each one's results being displayed before
|
|
|
|
continuing to the next command. However, a semicolon entered
|
2017-10-09 03:44:17 +02:00
|
|
|
as <literal>\;</literal> will not trigger command processing, so that the
|
2017-09-07 20:04:41 +02:00
|
|
|
command before it and the one after are effectively combined and
|
|
|
|
sent to the server in one request. So for example
|
|
|
|
<programlisting>
|
|
|
|
select 1\; select 2\; select 3;
|
|
|
|
</programlisting>
|
|
|
|
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,
|
2017-10-09 03:44:17 +02:00
|
|
|
unless there are explicit <command>BEGIN</command>/<command>COMMIT</command>
|
2017-09-07 20:04:41 +02:00
|
|
|
commands included in the string to divide it into multiple
|
2017-11-23 15:39:47 +01:00
|
|
|
transactions. (See <xref linkend="protocol-flow-multi-statement"/>
|
2017-09-07 20:04:41 +02:00
|
|
|
for more details about how the server handles multi-query strings.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
2002-08-10 05:56:24 +02:00
|
|
|
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<refsect3 id="app-psql-patterns" xreflabel="Patterns">
|
|
|
|
<title>Patterns</title>
|
2006-10-10 01:31:29 +02:00
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>patterns</primary>
|
|
|
|
<secondary>in psql and pg_dump</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2002-08-10 05:56:24 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The various <literal>\d</literal> commands accept a <replaceable
|
2002-08-10 05:56:24 +02:00
|
|
|
class="parameter">pattern</replaceable> parameter to specify the
|
2006-10-10 01:31:29 +02:00
|
|
|
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;
|
2017-10-09 03:44:17 +02:00
|
|
|
for example, <literal>\dt FOO</literal> will display the table named
|
|
|
|
<literal>foo</literal>. As in SQL names, placing double quotes around
|
2006-10-10 01:31:29 +02:00
|
|
|
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,
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>\dt "FOO""BAR"</literal> will display the table named
|
|
|
|
<literal>FOO"BAR</literal> (not <literal>foo"bar</literal>). Unlike the normal
|
2006-10-10 01:31:29 +02:00
|
|
|
rules for SQL names, you can put double quotes around just part
|
2017-10-09 03:44:17 +02:00
|
|
|
of a pattern, for instance <literal>\dt FOO"FOO"BAR</literal> will display
|
|
|
|
the table named <literal>fooFOObar</literal>.
|
2006-10-10 01:31:29 +02:00
|
|
|
</para>
|
|
|
|
|
2009-12-25 00:36:39 +01:00
|
|
|
<para>
|
|
|
|
Whenever the <replaceable class="parameter">pattern</replaceable> parameter
|
2017-10-09 03:44:17 +02:00
|
|
|
is omitted completely, the <literal>\d</literal> commands display all objects
|
2009-12-25 00:36:39 +01:00
|
|
|
that are visible in the current schema search path — this is
|
2017-10-09 03:44:17 +02:00
|
|
|
equivalent to using <literal>*</literal> as the pattern.
|
|
|
|
(An object is said to be <firstterm>visible</firstterm> if its
|
2009-12-25 00:36:39 +01:00
|
|
|
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,
|
2017-10-09 03:44:17 +02:00
|
|
|
use <literal>*.*</literal> as the pattern.
|
2009-12-25 00:36:39 +01:00
|
|
|
</para>
|
|
|
|
|
2006-10-10 01:31:29 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Within a pattern, <literal>*</literal> matches any sequence of characters
|
|
|
|
(including no characters) and <literal>?</literal> matches any single character.
|
2006-10-10 01:31:29 +02:00
|
|
|
(This notation is comparable to Unix shell file name patterns.)
|
2017-10-09 03:44:17 +02:00
|
|
|
For example, <literal>\dt int*</literal> displays tables whose names
|
|
|
|
begin with <literal>int</literal>. But within double quotes, <literal>*</literal>
|
|
|
|
and <literal>?</literal> lose these special meanings and are just matched
|
2006-10-10 01:31:29 +02:00
|
|
|
literally.
|
2002-08-10 05:56:24 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Allow db.schema.table patterns, but complain about random garbage.
psql, pg_dump, and pg_amcheck share code to process object name
patterns like 'foo*.bar*' to match all tables with names starting in
'bar' that are in schemas starting with 'foo'. Before v14, any number
of extra name parts were silently ignored, so a command line '\d
foo.bar.baz.bletch.quux' was interpreted as '\d bletch.quux'. In v14,
as a result of commit 2c8726c4b0a496608919d1f78a5abc8c9b6e0868, we
instead treated this as a request for table quux in a schema named
'foo.bar.baz.bletch'. That caused problems for people like Justin
Pryzby who were accustomed to copying strings of the form
db.schema.table from messages generated by PostgreSQL itself and using
them as arguments to \d.
Accordingly, revise things so that if an object name pattern contains
more parts than we're expecting, we throw an error, unless there's
exactly one extra part and it matches the current database name.
That way, thisdb.myschema.mytable is accepted as meaning just
myschema.mytable, but otherdb.myschema.mytable is an error, and so
is some.random.garbage.myschema.mytable.
Mark Dilger, per report from Justin Pryzby and discussion among
various people.
Discussion: https://www.postgresql.org/message-id/20211013165426.GD27491%40telsasoft.com
2022-04-20 17:02:35 +02:00
|
|
|
A relation pattern that contains a dot (<literal>.</literal>) is interpreted as a schema
|
2002-08-10 05:56:24 +02:00
|
|
|
name pattern followed by an object name pattern. For example,
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>\dt foo*.*bar*</literal> displays all tables whose table name
|
|
|
|
includes <literal>bar</literal> that are in schemas whose schema name
|
|
|
|
starts with <literal>foo</literal>. When no dot appears, then the pattern
|
2002-08-10 05:56:24 +02:00
|
|
|
matches only objects that are visible in the current schema search path.
|
2006-10-10 01:31:29 +02:00
|
|
|
Again, a dot within double quotes loses its special meaning and is matched
|
Allow db.schema.table patterns, but complain about random garbage.
psql, pg_dump, and pg_amcheck share code to process object name
patterns like 'foo*.bar*' to match all tables with names starting in
'bar' that are in schemas starting with 'foo'. Before v14, any number
of extra name parts were silently ignored, so a command line '\d
foo.bar.baz.bletch.quux' was interpreted as '\d bletch.quux'. In v14,
as a result of commit 2c8726c4b0a496608919d1f78a5abc8c9b6e0868, we
instead treated this as a request for table quux in a schema named
'foo.bar.baz.bletch'. That caused problems for people like Justin
Pryzby who were accustomed to copying strings of the form
db.schema.table from messages generated by PostgreSQL itself and using
them as arguments to \d.
Accordingly, revise things so that if an object name pattern contains
more parts than we're expecting, we throw an error, unless there's
exactly one extra part and it matches the current database name.
That way, thisdb.myschema.mytable is accepted as meaning just
myschema.mytable, but otherdb.myschema.mytable is an error, and so
is some.random.garbage.myschema.mytable.
Mark Dilger, per report from Justin Pryzby and discussion among
various people.
Discussion: https://www.postgresql.org/message-id/20211013165426.GD27491%40telsasoft.com
2022-04-20 17:02:35 +02:00
|
|
|
literally. A relation pattern that contains two dots (<literal>.</literal>)
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
A schema pattern that contains a dot (<literal>.</literal>) is interpreted
|
|
|
|
as a database name followed by a schema name pattern. For example,
|
|
|
|
<literal>\dn mydb.*foo*</literal> displays all schemas whose schema name
|
|
|
|
includes <literal>foo</literal>. 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.
|
2006-10-10 01:31:29 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Advanced users can use regular-expression notations such as character
|
2017-10-09 03:44:17 +02:00
|
|
|
classes, for example <literal>[0-9]</literal> to match any digit. All regular
|
2006-10-10 01:31:29 +02:00
|
|
|
expression special characters work as specified in
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="functions-posix-regexp"/>, except for <literal>.</literal> which
|
2017-10-09 03:44:17 +02:00
|
|
|
is taken as a separator as mentioned above, <literal>*</literal> which is
|
|
|
|
translated to the regular-expression notation <literal>.*</literal>,
|
|
|
|
<literal>?</literal> which is translated to <literal>.</literal>, and
|
|
|
|
<literal>$</literal> which is matched literally. You can emulate
|
2006-10-10 01:31:29 +02:00
|
|
|
these pattern characters at need by writing
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>?</literal> for <literal>.</literal>,
|
2006-10-10 01:31:29 +02:00
|
|
|
<literal>(<replaceable class="parameter">R</replaceable>+|)</literal> for
|
|
|
|
<literal><replaceable class="parameter">R</replaceable>*</literal>, or
|
|
|
|
<literal>(<replaceable class="parameter">R</replaceable>|)</literal> for
|
|
|
|
<literal><replaceable class="parameter">R</replaceable>?</literal>.
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>$</literal> is not needed as a regular-expression character since
|
2007-07-10 02:21:31 +02:00
|
|
|
the pattern must match the whole name, unlike the usual
|
2017-10-09 03:44:17 +02:00
|
|
|
interpretation of regular expressions (in other words, <literal>$</literal>
|
|
|
|
is automatically appended to your pattern). Write <literal>*</literal> at the
|
2007-07-10 02:21:31 +02:00
|
|
|
beginning and/or end if you don't wish the pattern to be anchored.
|
2006-10-10 01:31:29 +02:00
|
|
|
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
|
2017-10-09 03:44:17 +02:00
|
|
|
patterns (i.e., the argument of <literal>\do</literal>).
|
2002-08-10 05:56:24 +02:00
|
|
|
</para>
|
2006-10-10 01:31:29 +02:00
|
|
|
</refsect3>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect2>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect2>
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>Advanced Features</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<refsect3 id="app-psql-variables" xreflabel="Variables">
|
|
|
|
<title>Variables</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
<application>psql</application> provides variable substitution
|
2003-03-24 15:32:51 +01:00
|
|
|
features similar to common Unix command shells.
|
|
|
|
Variables are simply name/value pairs, where the value
|
2011-08-26 16:41:31 +02:00
|
|
|
can be any string of any length. The name must consist of letters
|
|
|
|
(including non-Latin letters), digits, and underscores.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To set a variable, use the <application>psql</application> meta-command
|
2011-08-26 19:52:23 +02:00
|
|
|
<command>\set</command>. For example,
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=> <userinput>\set foo bar</userinput>
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
2003-03-24 15:32:51 +01:00
|
|
|
sets the variable <literal>foo</literal> to the value
|
|
|
|
<literal>bar</literal>. To retrieve the content of the variable, precede
|
2011-08-26 19:52:23 +02:00
|
|
|
the name with a colon, for example:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=> <userinput>\echo :foo</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
bar
|
2011-08-26 19:52:23 +02:00
|
|
|
</programlisting>
|
|
|
|
This works in both regular SQL commands and meta-commands; there is
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
more detail in <xref linkend="app-psql-interpolation"/>, below.
|
2011-08-26 19:52:23 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If you call <command>\set</command> without a second argument, the
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
variable is set to an empty-string value. To unset (i.e., delete)
|
2011-08-26 19:52:23 +02:00
|
|
|
a variable, use the command <command>\unset</command>. To show the
|
|
|
|
values of all variables, call <command>\set</command> without any argument.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The arguments of <command>\set</command> are subject to the same
|
|
|
|
substitution rules as with other commands. Thus you can construct
|
|
|
|
interesting references such as <literal>\set :foo
|
|
|
|
'something'</literal> and get <quote>soft links</quote> or
|
|
|
|
<quote>variable variables</quote> of <productname>Perl</productname>
|
|
|
|
or <productname><acronym>PHP</acronym></productname> fame,
|
|
|
|
respectively. Unfortunately (or fortunately?), there is no way to do
|
|
|
|
anything useful with these constructs. On the other hand,
|
|
|
|
<literal>\set bar :foo</literal> is a perfectly valid way to copy a
|
|
|
|
variable.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<para>
|
2011-08-26 16:41:31 +02:00
|
|
|
A number of these variables are treated specially
|
|
|
|
by <application>psql</application>. They represent certain option
|
2002-06-20 18:00:44 +02:00
|
|
|
settings that can be changed at run time by altering the value of
|
2011-08-26 16:41:31 +02:00
|
|
|
the variable, or in some cases represent changeable state of
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
<application>psql</application>.
|
|
|
|
By convention, all specially treated variables' names
|
2011-08-26 16:41:31 +02:00
|
|
|
consist of all upper-case ASCII letters (and possibly digits and
|
2002-06-20 18:00:44 +02:00
|
|
|
underscores). To ensure maximum compatibility in the future, avoid
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
using such variable names for your own purposes.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Variables that control <application>psql</application>'s behavior
|
2017-10-09 03:44:17 +02:00
|
|
|
generally cannot be unset or set to invalid values. An <literal>\unset</literal>
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
command is allowed but is interpreted as setting the variable to its
|
2017-10-09 03:44:17 +02:00
|
|
|
default value. A <literal>\set</literal> command without a second argument is
|
|
|
|
interpreted as setting the variable to <literal>on</literal>, for control
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
variables that accept that value, and is rejected for others. Also,
|
2017-10-09 03:44:17 +02:00
|
|
|
control variables that accept the values <literal>on</literal>
|
|
|
|
and <literal>off</literal> will also accept other common spellings of Boolean
|
|
|
|
values, such as <literal>true</literal> and <literal>false</literal>.
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The specially treated variables are:
|
2003-03-24 15:32:51 +01:00
|
|
|
</para>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<variablelist>
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-autocommit">
|
2014-05-07 03:28:58 +02:00
|
|
|
<term>
|
|
|
|
<varname>AUTOCOMMIT</varname>
|
|
|
|
<indexterm>
|
|
|
|
<primary>autocommit</primary>
|
|
|
|
<secondary>psql</secondary>
|
|
|
|
</indexterm>
|
|
|
|
</term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When <literal>on</literal> (the default), each SQL command is automatically
|
2004-06-18 08:14:31 +02:00
|
|
|
committed upon successful completion. To postpone commit in this
|
2017-10-09 03:44:17 +02:00
|
|
|
mode, you must enter a <command>BEGIN</command> or <command>START
|
|
|
|
TRANSACTION</command> SQL command. When <literal>off</literal> or unset, SQL
|
2004-06-18 08:14:31 +02:00
|
|
|
commands are not committed until you explicitly issue
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>COMMIT</command> or <command>END</command>. The autocommit-off
|
|
|
|
mode works by issuing an implicit <command>BEGIN</command> for you, just
|
2004-06-18 08:14:31 +02:00
|
|
|
before any command that is not already in a transaction block and
|
2017-10-09 03:44:17 +02:00
|
|
|
is not itself a <command>BEGIN</command> or other transaction-control
|
2004-09-20 20:51:19 +02:00
|
|
|
command, nor a command that cannot be executed inside a transaction
|
2017-10-09 03:44:17 +02:00
|
|
|
block (such as <command>VACUUM</command>).
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
In autocommit-off mode, you must explicitly abandon any failed
|
2017-10-09 03:44:17 +02:00
|
|
|
transaction by entering <command>ABORT</command> or <command>ROLLBACK</command>.
|
2004-06-18 08:14:31 +02:00
|
|
|
Also keep in mind that if you exit the session
|
|
|
|
without committing, your work will be lost.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The autocommit-on mode is <productname>PostgreSQL</productname>'s traditional
|
2004-06-18 08:14:31 +02:00
|
|
|
behavior, but autocommit-off is closer to the SQL spec. If you
|
Update reference documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 00:26:05 +01:00
|
|
|
prefer autocommit-off, you might wish to set it in the system-wide
|
2005-01-06 19:29:11 +01:00
|
|
|
<filename>psqlrc</filename> file or your
|
|
|
|
<filename>~/.psqlrc</filename> file.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
2003-06-28 02:12:40 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-comp-keyword-case">
|
2012-05-08 20:03:45 +02:00
|
|
|
<term><varname>COMP_KEYWORD_CASE</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Determines which letter case to use when completing an SQL key word.
|
|
|
|
If set to <literal>lower</literal> or <literal>upper</literal>, the
|
|
|
|
completed word will be in lower or upper case, respectively. If set
|
|
|
|
to <literal>preserve-lower</literal>
|
|
|
|
or <literal>preserve-upper</literal> (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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-dbname">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>DBNAME</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The name of the database you are currently connected to. This is
|
|
|
|
set every time you connect to a database (including program
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
start-up), but can be changed or unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-echo">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>ECHO</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-02-01 00:35:13 +01:00
|
|
|
If set to <literal>all</literal>, 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
|
2004-06-18 08:14:31 +02:00
|
|
|
start-up, use the switch <option>-a</option>. If set to
|
|
|
|
<literal>queries</literal>,
|
2015-02-01 00:35:13 +01:00
|
|
|
<application>psql</application> prints each query to standard output
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
as it is sent to the server. The switch to select this behavior is
|
2015-02-01 00:35:13 +01:00
|
|
|
<option>-e</option>. If set to <literal>errors</literal>, then only
|
2014-07-10 07:27:54 +02:00
|
|
|
failed queries are displayed on standard error output. The switch
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
for this behavior is <option>-b</option>. If set to
|
|
|
|
<literal>none</literal> (the default), then no queries are displayed.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-echo-hidden">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>ECHO_HIDDEN</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When this variable is set to <literal>on</literal> and a backslash command
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
queries the database, the query is first shown.
|
|
|
|
This feature helps you to study
|
2004-06-18 08:14:31 +02:00
|
|
|
<productname>PostgreSQL</productname> internals and provide
|
|
|
|
similar functionality in your own programs. (To select this behavior
|
|
|
|
on program start-up, use the switch <option>-E</option>.) If you set
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
this variable to the value <literal>noexec</literal>, the queries are
|
2004-06-18 08:14:31 +02:00
|
|
|
just shown but are not actually sent to the server and executed.
|
2017-10-09 03:44:17 +02:00
|
|
|
The default value is <literal>off</literal>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-encoding">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>ENCODING</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
The current client character set encoding.
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
This is set every time you connect to a database (including
|
|
|
|
program start-up), and when you change the encoding
|
2017-10-09 03:44:17 +02:00
|
|
|
with <literal>\encoding</literal>, but it can be changed or unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-02-20 15:29:21 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-error">
|
2017-09-13 01:27:48 +02:00
|
|
|
<term><varname>ERROR</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>true</literal> if the last SQL query failed, <literal>false</literal> if
|
|
|
|
it succeeded. See also <varname>SQLSTATE</varname>.
|
2017-09-13 01:27:48 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-fetch-count">
|
2006-08-30 00:25:08 +02:00
|
|
|
<term><varname>FETCH_COUNT</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
If this variable is set to an integer value greater than zero,
|
2006-08-30 00:25:08 +02:00
|
|
|
the results of <command>SELECT</command> 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.
|
Update reference documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 00:26:05 +01:00
|
|
|
Keep in mind that when using this feature, a query might
|
2006-08-30 00:25:08 +02:00
|
|
|
fail after having already displayed some rows.
|
|
|
|
</para>
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
|
2006-08-30 00:25:08 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
Although you can use any output format with this feature,
|
2017-10-09 03:44:17 +02:00
|
|
|
the default <literal>aligned</literal> format tends to look bad
|
2006-08-30 00:25:08 +02:00
|
|
|
because each group of <varname>FETCH_COUNT</varname> rows
|
|
|
|
will be formatted separately, leading to varying column
|
|
|
|
widths across the row groups. The other output formats work better.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-hide-tableam">
|
2021-05-21 17:10:09 +02:00
|
|
|
<term><varname>HIDE_TABLEAM</varname></term>
|
Allow configurable LZ4 TOAST compression.
There is now a per-column COMPRESSION option which can be set to pglz
(the default, and the only option in up until now) or lz4. Or, if you
like, you can set the new default_toast_compression GUC to lz4, and
then that will be the default for new table columns for which no value
is specified. We don't have lz4 support in the PostgreSQL code, so
to use lz4 compression, PostgreSQL must be built --with-lz4.
In general, TOAST compression means compression of individual column
values, not the whole tuple, and those values can either be compressed
inline within the tuple or compressed and then stored externally in
the TOAST table, so those properties also apply to this feature.
Prior to this commit, a TOAST pointer has two unused bits as part of
the va_extsize field, and a compessed datum has two unused bits as
part of the va_rawsize field. These bits are unused because the length
of a varlena is limited to 1GB; we now use them to indicate the
compression type that was used. This means we only have bit space for
2 more built-in compresison types, but we could work around that
problem, if necessary, by introducing a new vartag_external value for
any further types we end up wanting to add. Hopefully, it won't be
too important to offer a wide selection of algorithms here, since
each one we add not only takes more coding but also adds a build
dependency for every packager. Nevertheless, it seems worth doing
at least this much, because LZ4 gets better compression than PGLZ
with less CPU usage.
It's possible for LZ4-compressed datums to leak into composite type
values stored on disk, just as it is for PGLZ. It's also possible for
LZ4-compressed attributes to be copied into a different table via SQL
commands such as CREATE TABLE AS or INSERT .. SELECT. It would be
expensive to force such values to be decompressed, so PostgreSQL has
never done so. For the same reasons, we also don't force recompression
of already-compressed values even if the target table prefers a
different compression method than was used for the source data. These
architectural decisions are perhaps arguable but revisiting them is
well beyond the scope of what seemed possible to do as part of this
project. However, it's relatively cheap to recompress as part of
VACUUM FULL or CLUSTER, so this commit adjusts those commands to do
so, if the configured compression method of the table happens not to
match what was used for some column value stored therein.
Dilip Kumar. The original patches on which this work was based were
written by Ildus Kurbangaliev, and those were patches were based on
even earlier work by Nikita Glukhov, but the design has since changed
very substantially, since allow a potentially large number of
compression methods that could be added and dropped on a running
system proved too problematic given some of the architectural issues
mentioned above; the choice of which specific compression method to
add first is now different; and a lot of the code has been heavily
refactored. More recently, Justin Przyby helped quite a bit with
testing and reviewing and this version also includes some code
contributions from him. Other design input and review from Tomas
Vondra, Álvaro Herrera, Andres Freund, Oleg Bartunov, Alexander
Korotkov, and me.
Discussion: http://postgr.es/m/20170907194236.4cefce96%40wp.localdomain
Discussion: http://postgr.es/m/CAFiTN-uUpX3ck%3DK0mLEk-G_kUQY%3DSNOTeqdaNRR9FMdQrHKebw%40mail.gmail.com
2021-03-19 20:10:38 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-05-21 17:10:09 +02:00
|
|
|
If this variable is set to <literal>true</literal>, a table's access
|
|
|
|
method details are not displayed. This is mainly useful for
|
|
|
|
regression tests.
|
Allow configurable LZ4 TOAST compression.
There is now a per-column COMPRESSION option which can be set to pglz
(the default, and the only option in up until now) or lz4. Or, if you
like, you can set the new default_toast_compression GUC to lz4, and
then that will be the default for new table columns for which no value
is specified. We don't have lz4 support in the PostgreSQL code, so
to use lz4 compression, PostgreSQL must be built --with-lz4.
In general, TOAST compression means compression of individual column
values, not the whole tuple, and those values can either be compressed
inline within the tuple or compressed and then stored externally in
the TOAST table, so those properties also apply to this feature.
Prior to this commit, a TOAST pointer has two unused bits as part of
the va_extsize field, and a compessed datum has two unused bits as
part of the va_rawsize field. These bits are unused because the length
of a varlena is limited to 1GB; we now use them to indicate the
compression type that was used. This means we only have bit space for
2 more built-in compresison types, but we could work around that
problem, if necessary, by introducing a new vartag_external value for
any further types we end up wanting to add. Hopefully, it won't be
too important to offer a wide selection of algorithms here, since
each one we add not only takes more coding but also adds a build
dependency for every packager. Nevertheless, it seems worth doing
at least this much, because LZ4 gets better compression than PGLZ
with less CPU usage.
It's possible for LZ4-compressed datums to leak into composite type
values stored on disk, just as it is for PGLZ. It's also possible for
LZ4-compressed attributes to be copied into a different table via SQL
commands such as CREATE TABLE AS or INSERT .. SELECT. It would be
expensive to force such values to be decompressed, so PostgreSQL has
never done so. For the same reasons, we also don't force recompression
of already-compressed values even if the target table prefers a
different compression method than was used for the source data. These
architectural decisions are perhaps arguable but revisiting them is
well beyond the scope of what seemed possible to do as part of this
project. However, it's relatively cheap to recompress as part of
VACUUM FULL or CLUSTER, so this commit adjusts those commands to do
so, if the configured compression method of the table happens not to
match what was used for some column value stored therein.
Dilip Kumar. The original patches on which this work was based were
written by Ildus Kurbangaliev, and those were patches were based on
even earlier work by Nikita Glukhov, but the design has since changed
very substantially, since allow a potentially large number of
compression methods that could be added and dropped on a running
system proved too problematic given some of the architectural issues
mentioned above; the choice of which specific compression method to
add first is now different; and a lot of the code has been heavily
refactored. More recently, Justin Przyby helped quite a bit with
testing and reviewing and this version also includes some code
contributions from him. Other design input and review from Tomas
Vondra, Álvaro Herrera, Andres Freund, Oleg Bartunov, Alexander
Korotkov, and me.
Discussion: http://postgr.es/m/20170907194236.4cefce96%40wp.localdomain
Discussion: http://postgr.es/m/CAFiTN-uUpX3ck%3DK0mLEk-G_kUQY%3DSNOTeqdaNRR9FMdQrHKebw%40mail.gmail.com
2021-03-19 20:10:38 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-hide-toast-compression">
|
2021-05-21 17:10:09 +02:00
|
|
|
<term><varname>HIDE_TOAST_COMPRESSION</varname></term>
|
tableam: introduce table AM infrastructure.
This introduces the concept of table access methods, i.e. CREATE
ACCESS METHOD ... TYPE TABLE and
CREATE TABLE ... USING (storage-engine).
No table access functionality is delegated to table AMs as of this
commit, that'll be done in following commits.
Subsequent commits will incrementally abstract table access
functionality to be routed through table access methods. That change
is too large to be reviewed & committed at once, so it'll be done
incrementally.
Docs will be updated at the end, as adding them incrementally would
likely make them less coherent, and definitely is a lot more work,
without a lot of benefit.
Table access methods are specified similar to index access methods,
i.e. pg_am.amhandler returns, as INTERNAL, a pointer to a struct with
callbacks. In contrast to index AMs that struct needs to live as long
as a backend, typically that's achieved by just returning a pointer to
a constant struct.
Psql's \d+ now displays a table's access method. That can be disabled
with HIDE_TABLEAM=true, which is mainly useful so regression tests can
be run against different AMs. It's quite possible that this behaviour
still needs to be fine tuned.
For now it's not allowed to set a table AM for a partitioned table, as
we've not resolved how partitions would inherit that. Disallowing
allows us to introduce, if we decide that's the way forward, such a
behaviour without a compatibility break.
Catversion bumped, to add the heap table AM and references to it.
Author: Haribabu Kommi, Andres Freund, Alvaro Herrera, Dimitri Golgov and others
Discussion:
https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
https://postgr.es/m/20160812231527.GA690404@alvherre.pgsql
https://postgr.es/m/20190107235616.6lur25ph22u5u5av@alap3.anarazel.de
https://postgr.es/m/20190304234700.w5tmhducs5wxgzls@alap3.anarazel.de
2019-03-06 18:54:38 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-05-21 17:10:09 +02:00
|
|
|
If this variable is set to <literal>true</literal>, column
|
|
|
|
compression method details are not displayed. This is mainly
|
|
|
|
useful for regression tests.
|
tableam: introduce table AM infrastructure.
This introduces the concept of table access methods, i.e. CREATE
ACCESS METHOD ... TYPE TABLE and
CREATE TABLE ... USING (storage-engine).
No table access functionality is delegated to table AMs as of this
commit, that'll be done in following commits.
Subsequent commits will incrementally abstract table access
functionality to be routed through table access methods. That change
is too large to be reviewed & committed at once, so it'll be done
incrementally.
Docs will be updated at the end, as adding them incrementally would
likely make them less coherent, and definitely is a lot more work,
without a lot of benefit.
Table access methods are specified similar to index access methods,
i.e. pg_am.amhandler returns, as INTERNAL, a pointer to a struct with
callbacks. In contrast to index AMs that struct needs to live as long
as a backend, typically that's achieved by just returning a pointer to
a constant struct.
Psql's \d+ now displays a table's access method. That can be disabled
with HIDE_TABLEAM=true, which is mainly useful so regression tests can
be run against different AMs. It's quite possible that this behaviour
still needs to be fine tuned.
For now it's not allowed to set a table AM for a partitioned table, as
we've not resolved how partitions would inherit that. Disallowing
allows us to introduce, if we decide that's the way forward, such a
behaviour without a compatibility break.
Catversion bumped, to add the heap table AM and references to it.
Author: Haribabu Kommi, Andres Freund, Alvaro Herrera, Dimitri Golgov and others
Discussion:
https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
https://postgr.es/m/20160812231527.GA690404@alvherre.pgsql
https://postgr.es/m/20190107235616.6lur25ph22u5u5av@alap3.anarazel.de
https://postgr.es/m/20190304234700.w5tmhducs5wxgzls@alap3.anarazel.de
2019-03-06 18:54:38 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-histcontrol">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>HISTCONTROL</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
If this variable is set to <literal>ignorespace</literal>,
|
|
|
|
lines which begin with a space are not entered into the history
|
|
|
|
list. If set to a value of <literal>ignoredups</literal>, lines
|
|
|
|
matching the previous history line are not entered. A value of
|
|
|
|
<literal>ignoreboth</literal> combines the two options. If
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
set to <literal>none</literal> (the default), all lines
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
read in interactive mode are saved on the history list.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2000-01-14 23:18:03 +01:00
|
|
|
<note>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
This feature was shamelessly plagiarized from
|
2003-03-24 15:32:51 +01:00
|
|
|
<application>Bash</application>.
|
2000-01-14 23:18:03 +01:00
|
|
|
</para>
|
2005-06-10 17:34:26 +02:00
|
|
|
</note>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-histfile">
|
2005-06-10 17:34:26 +02:00
|
|
|
<term><varname>HISTFILE</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
The file name that will be used to store the history list. If unset,
|
|
|
|
the file name is taken from the <envar>PSQL_HISTORY</envar>
|
|
|
|
environment variable. If that is not set either, the default
|
|
|
|
is <filename>~/.psql_history</filename>,
|
|
|
|
or <filename>%APPDATA%\postgresql\psql_history</filename> on Windows.
|
|
|
|
For example, putting:
|
2005-06-10 17:34:26 +02:00
|
|
|
<programlisting>
|
2021-04-15 09:45:34 +02:00
|
|
|
\set HISTFILE ~/.psql_history-:DBNAME
|
2005-06-10 17:34:26 +02:00
|
|
|
</programlisting>
|
2005-11-01 22:09:51 +01:00
|
|
|
in <filename>~/.psqlrc</filename> will cause
|
|
|
|
<application>psql</application> to maintain a separate history for
|
|
|
|
each database.
|
2005-06-10 17:34:26 +02:00
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
This feature was shamelessly plagiarized from
|
|
|
|
<application>Bash</application>.
|
|
|
|
</para>
|
2000-01-14 23:18:03 +01:00
|
|
|
</note>
|
2004-06-18 08:14:31 +02:00
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-histsize">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>HISTSIZE</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
Clean up psql's behavior for a few more control variables.
Modify FETCH_COUNT to always have a defined value, like other control
variables, mainly so it will always appear in "\set" output.
Add hooks to force HISTSIZE to be defined and require it to have an
integer value. (I don't see any point in allowing it to be set to
non-integral values.)
Add hooks to force IGNOREEOF to be defined and require it to have an
integer value. Unlike the other cases, here we're trying to be
bug-compatible with a rather bogus externally-defined behavior, so I think
we need to continue to allow "\set IGNOREEOF whatever". Fix it so that
the substitution hook silently replace non-numeric values with "10",
so that the stored value always reflects what we're really doing.
Add a dummy assign hook for HISTFILE, just so it's always in
variables.c's list. We can't require it to be defined always, because
that would break the interaction with the PSQL_HISTORY environment
variable, so there isn't any change in visible behavior here.
Remove tab-complete.c's private list of known variable names, since that's
really a maintenance nuisance. Given the preceding changes, there are no
control variables it won't show anyway. This does mean that if for some
reason you've unset one of the status variables (DBNAME, HOST, etc), that
variable would not appear in tab completion for \set. But I think that's
fine, for at least two reasons: we shouldn't be encouraging people to use
those variables as regular variables, and if someone does do so anyway,
why shouldn't it act just like a regular variable?
Remove ugly and no-longer-used-anywhere GetVariableNum(). In general,
future additions of integer-valued control variables should follow the
paradigm of adding an assign hook using ParseVariableNum(), so there's
no reason to expect we'd need this again later.
Discussion: https://postgr.es/m/17516.1485973973@sss.pgh.pa.us
2017-02-03 02:16:17 +01:00
|
|
|
The maximum number of commands to store in the command history
|
|
|
|
(default 500). If set to a negative value, no limit is applied.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2000-01-14 23:18:03 +01:00
|
|
|
<note>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
This feature was shamelessly plagiarized from
|
2003-03-24 15:32:51 +01:00
|
|
|
<application>Bash</application>.
|
2000-01-14 23:18:03 +01:00
|
|
|
</para>
|
|
|
|
</note>
|
2004-06-18 08:14:31 +02:00
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-host">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>HOST</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The database server host you are currently connected to. This is
|
|
|
|
set every time you connect to a database (including program
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
start-up), but can be changed or unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-ignoreeof">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>IGNOREEOF</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If set to 1 or less, sending an <acronym>EOF</acronym> character (usually
|
|
|
|
<keycombo action="simul"><keycap>Control</keycap><keycap>D</keycap></keycombo>)
|
2002-09-21 20:32:54 +02:00
|
|
|
to an interactive session of <application>psql</application>
|
Clean up psql's behavior for a few more control variables.
Modify FETCH_COUNT to always have a defined value, like other control
variables, mainly so it will always appear in "\set" output.
Add hooks to force HISTSIZE to be defined and require it to have an
integer value. (I don't see any point in allowing it to be set to
non-integral values.)
Add hooks to force IGNOREEOF to be defined and require it to have an
integer value. Unlike the other cases, here we're trying to be
bug-compatible with a rather bogus externally-defined behavior, so I think
we need to continue to allow "\set IGNOREEOF whatever". Fix it so that
the substitution hook silently replace non-numeric values with "10",
so that the stored value always reflects what we're really doing.
Add a dummy assign hook for HISTFILE, just so it's always in
variables.c's list. We can't require it to be defined always, because
that would break the interaction with the PSQL_HISTORY environment
variable, so there isn't any change in visible behavior here.
Remove tab-complete.c's private list of known variable names, since that's
really a maintenance nuisance. Given the preceding changes, there are no
control variables it won't show anyway. This does mean that if for some
reason you've unset one of the status variables (DBNAME, HOST, etc), that
variable would not appear in tab completion for \set. But I think that's
fine, for at least two reasons: we shouldn't be encouraging people to use
those variables as regular variables, and if someone does do so anyway,
why shouldn't it act just like a regular variable?
Remove ugly and no-longer-used-anywhere GetVariableNum(). In general,
future additions of integer-valued control variables should follow the
paradigm of adding an assign hook using ParseVariableNum(), so there's
no reason to expect we'd need this again later.
Discussion: https://postgr.es/m/17516.1485973973@sss.pgh.pa.us
2017-02-03 02:16:17 +01:00
|
|
|
will terminate the application. If set to a larger numeric value,
|
2017-10-09 03:44:17 +02:00
|
|
|
that many consecutive <acronym>EOF</acronym> characters must be typed to
|
Clean up psql's behavior for a few more control variables.
Modify FETCH_COUNT to always have a defined value, like other control
variables, mainly so it will always appear in "\set" output.
Add hooks to force HISTSIZE to be defined and require it to have an
integer value. (I don't see any point in allowing it to be set to
non-integral values.)
Add hooks to force IGNOREEOF to be defined and require it to have an
integer value. Unlike the other cases, here we're trying to be
bug-compatible with a rather bogus externally-defined behavior, so I think
we need to continue to allow "\set IGNOREEOF whatever". Fix it so that
the substitution hook silently replace non-numeric values with "10",
so that the stored value always reflects what we're really doing.
Add a dummy assign hook for HISTFILE, just so it's always in
variables.c's list. We can't require it to be defined always, because
that would break the interaction with the PSQL_HISTORY environment
variable, so there isn't any change in visible behavior here.
Remove tab-complete.c's private list of known variable names, since that's
really a maintenance nuisance. Given the preceding changes, there are no
control variables it won't show anyway. This does mean that if for some
reason you've unset one of the status variables (DBNAME, HOST, etc), that
variable would not appear in tab completion for \set. But I think that's
fine, for at least two reasons: we shouldn't be encouraging people to use
those variables as regular variables, and if someone does do so anyway,
why shouldn't it act just like a regular variable?
Remove ugly and no-longer-used-anywhere GetVariableNum(). In general,
future additions of integer-valued control variables should follow the
paradigm of adding an assign hook using ParseVariableNum(), so there's
no reason to expect we'd need this again later.
Discussion: https://postgr.es/m/17516.1485973973@sss.pgh.pa.us
2017-02-03 02:16:17 +01:00
|
|
|
make an interactive session terminate. If the variable is set to a
|
2017-09-11 17:20:47 +02:00
|
|
|
non-numeric value, it is interpreted as 10. The default is 0.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2000-01-14 23:18:03 +01:00
|
|
|
<note>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
This feature was shamelessly plagiarized from
|
2003-03-24 15:32:51 +01:00
|
|
|
<application>Bash</application>.
|
2000-01-14 23:18:03 +01:00
|
|
|
</para>
|
|
|
|
</note>
|
2004-06-18 08:14:31 +02:00
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-lastoid">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>LASTOID</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-09-21 20:32:54 +02:00
|
|
|
The value of the last affected OID, as returned from an
|
2011-01-06 03:32:10 +01:00
|
|
|
<command>INSERT</command> or <command>\lo_import</command>
|
2002-06-20 18:00:44 +02:00
|
|
|
command. This variable is only guaranteed to be valid until
|
|
|
|
after the result of the next <acronym>SQL</acronym> command has
|
|
|
|
been displayed.
|
2019-04-18 02:22:56 +02:00
|
|
|
<productname>PostgreSQL</productname> servers since version 12 do not
|
|
|
|
support OID system columns anymore, thus LASTOID will always be 0
|
|
|
|
following <command>INSERT</command> when targeting such servers.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-last-error-message">
|
2017-09-13 01:27:48 +02:00
|
|
|
<term><varname>LAST_ERROR_MESSAGE</varname></term>
|
|
|
|
<term><varname>LAST_ERROR_SQLSTATE</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The primary error message and associated SQLSTATE code for the most
|
2017-10-09 03:44:17 +02:00
|
|
|
recent failed query in the current <application>psql</application> session, or
|
|
|
|
an empty string and <literal>00000</literal> if no error has occurred in
|
2017-09-13 01:27:48 +02:00
|
|
|
the current session.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-on-error-rollback">
|
2014-05-07 03:28:58 +02:00
|
|
|
<term>
|
|
|
|
<varname>ON_ERROR_ROLLBACK</varname>
|
|
|
|
<indexterm>
|
|
|
|
<primary>rollback</primary>
|
|
|
|
<secondary>psql</secondary>
|
|
|
|
</indexterm>
|
|
|
|
</term>
|
2005-04-28 15:09:59 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When set to <literal>on</literal>, if a statement in a transaction block
|
2005-04-28 15:09:59 +02:00
|
|
|
generates an error, the error is ignored and the transaction
|
2017-10-09 03:44:17 +02:00
|
|
|
continues. When set to <literal>interactive</literal>, such errors are only
|
2005-04-28 15:09:59 +02:00
|
|
|
ignored in interactive sessions, and not when reading script
|
2017-10-09 03:44:17 +02:00
|
|
|
files. When set to <literal>off</literal> (the default), a statement in a
|
2005-04-28 15:09:59 +02:00
|
|
|
transaction block that generates an error aborts the entire
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
transaction. The error rollback mode works by issuing an
|
2017-10-09 03:44:17 +02:00
|
|
|
implicit <command>SAVEPOINT</command> for you, just before each command
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
that is in a transaction block, and then rolling back to the
|
|
|
|
savepoint if the command fails.
|
2005-04-28 15:09:59 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-on-error-stop">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>ON_ERROR_STOP</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-06-14 17:05:54 +02:00
|
|
|
By default, command processing continues after an error. When this
|
2017-10-09 03:44:17 +02:00
|
|
|
variable is set to <literal>on</literal>, processing will instead stop
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
immediately. In interactive mode,
|
2011-06-14 17:05:54 +02:00
|
|
|
<application>psql</application> will return to the command prompt;
|
|
|
|
otherwise, <application>psql</application> will exit, returning
|
|
|
|
error code 3 to distinguish this case from fatal error
|
|
|
|
conditions, which are reported using error code 1. In either case,
|
2011-08-27 07:07:58 +02:00
|
|
|
any currently running scripts (the top-level script, if any, and any
|
2011-06-14 17:05:54 +02:00
|
|
|
other scripts which it may have in invoked) will be terminated
|
2011-08-27 07:07:58 +02:00
|
|
|
immediately. If the top-level command string contained multiple SQL
|
2011-06-14 17:05:54 +02:00
|
|
|
commands, processing will stop with the current command.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-02-10 21:08:58 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-port">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>PORT</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The database server port to which you are currently connected.
|
|
|
|
This is set every time you connect to a database (including
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
program start-up), but can be changed or unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-prompt">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>PROMPT1</varname></term>
|
|
|
|
<term><varname>PROMPT2</varname></term>
|
|
|
|
<term><varname>PROMPT3</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
These specify what the prompts <application>psql</application>
|
|
|
|
issues should look like. See <xref
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
linkend="app-psql-prompting"/> below.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-quiet">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>QUIET</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Setting this variable to <literal>on</literal> is equivalent to the command
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
line option <option>-q</option>. It is probably not too useful in
|
2004-06-18 08:14:31 +02:00
|
|
|
interactive mode.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-row-count">
|
2017-09-13 01:27:48 +02:00
|
|
|
<term><varname>ROW_COUNT</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-server-version-name">
|
2017-09-05 16:51:36 +02:00
|
|
|
<term><varname>SERVER_VERSION_NAME</varname></term>
|
|
|
|
<term><varname>SERVER_VERSION_NUM</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The server's version number as a string, for
|
2017-10-09 03:44:17 +02:00
|
|
|
example <literal>9.6.2</literal>, <literal>10.1</literal> or <literal>11beta1</literal>,
|
2017-09-05 16:51:36 +02:00
|
|
|
and in numeric form, for
|
2017-10-09 03:44:17 +02:00
|
|
|
example <literal>90602</literal> or <literal>100001</literal>.
|
2017-09-05 16:51:36 +02:00
|
|
|
These are set every time you connect to a database
|
|
|
|
(including program start-up), but can be changed or unset.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-03-21 18:03:42 +01:00
|
|
|
<varlistentry id="app-psql-variables-shell-error">
|
|
|
|
<term><varname>SHELL_ERROR</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>true</literal> if the last shell command
|
|
|
|
failed, <literal>false</literal> if it succeeded.
|
2023-04-06 23:33:38 +02:00
|
|
|
This applies to shell commands invoked via the <literal>\!</literal>,
|
|
|
|
<literal>\g</literal>, <literal>\o</literal>, <literal>\w</literal>,
|
|
|
|
and <literal>\copy</literal> meta-commands, as well as backquote
|
|
|
|
(<literal>`</literal>) expansion. Note that
|
|
|
|
for <literal>\o</literal>, this variable is updated when the output
|
|
|
|
pipe is closed by the next <literal>\o</literal> command.
|
2023-03-21 18:03:42 +01:00
|
|
|
See also <varname>SHELL_EXIT_CODE</varname>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry id="app-psql-variables-shell-exit-code">
|
|
|
|
<term><varname>SHELL_EXIT_CODE</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The exit status returned by the last shell command.
|
|
|
|
0–127 represent program exit codes, 128–255
|
|
|
|
indicate termination by a signal, and -1 indicates failure
|
|
|
|
to launch a program or to collect its exit status.
|
2023-04-06 23:33:38 +02:00
|
|
|
This applies to shell commands invoked via the <literal>\!</literal>,
|
|
|
|
<literal>\g</literal>, <literal>\o</literal>, <literal>\w</literal>,
|
|
|
|
and <literal>\copy</literal> meta-commands, as well as backquote
|
|
|
|
(<literal>`</literal>) expansion. Note that
|
|
|
|
for <literal>\o</literal>, this variable is updated when the output
|
|
|
|
pipe is closed by the next <literal>\o</literal> command.
|
2023-03-21 18:03:42 +01:00
|
|
|
See also <varname>SHELL_ERROR</varname>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-show-all-results">
|
2022-04-04 14:57:17 +02:00
|
|
|
<term><varname>SHOW_ALL_RESULTS</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When this variable is set to <literal>off</literal>, only the last
|
|
|
|
result of a combined query (<literal>\;</literal>) is shown instead of
|
|
|
|
all of them. The default is <literal>on</literal>. The off behavior
|
|
|
|
is for compatibility with older versions of psql.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-show-context">
|
2015-09-05 17:58:20 +02:00
|
|
|
<term><varname>SHOW_CONTEXT</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This variable can be set to the
|
2017-10-09 03:44:17 +02:00
|
|
|
values <literal>never</literal>, <literal>errors</literal>, or <literal>always</literal>
|
|
|
|
to control whether <literal>CONTEXT</literal> fields are displayed in
|
|
|
|
messages from the server. The default is <literal>errors</literal> (meaning
|
2015-09-05 17:58:20 +02:00
|
|
|
that context will be shown in error messages, but not in notice or
|
|
|
|
warning messages). This setting has no effect
|
2019-04-04 23:22:02 +02:00
|
|
|
when <varname>VERBOSITY</varname> is set to <literal>terse</literal>
|
|
|
|
or <literal>sqlstate</literal>.
|
2017-10-09 03:44:17 +02:00
|
|
|
(See also <command>\errverbose</command>, for use when you want a verbose
|
2016-04-03 18:29:55 +02:00
|
|
|
version of the error you just got.)
|
2015-09-05 17:58:20 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-singleline">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>SINGLELINE</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Setting this variable to <literal>on</literal> is equivalent to the command
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
line option <option>-S</option>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-singlestep">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>SINGLESTEP</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Setting this variable to <literal>on</literal> is equivalent to the command
|
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
2014-12-31 18:16:53 +01:00
|
|
|
line option <option>-s</option>.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
2017-09-13 01:27:48 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-sqlstate">
|
2017-09-13 01:27:48 +02:00
|
|
|
<term><varname>SQLSTATE</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
The error code (see <xref linkend="errcodes-appendix"/>) associated
|
2017-10-09 03:44:17 +02:00
|
|
|
with the last SQL query's failure, or <literal>00000</literal> if it
|
2017-09-13 01:27:48 +02:00
|
|
|
succeeded.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-user">
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>USER</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The database user you are currently connected as. This is set
|
|
|
|
every time you connect to a database (including program
|
Improve psql's behavior for \set and \unset of its control variables.
This commit improves on the results of commit 511ae628f in two ways:
1. It restores the historical behavior that "\set FOO" is interpreted
as setting FOO to "on", if FOO is a boolean control variable. We
already found one test script that was expecting that behavior, and
the psql documentation certainly does nothing to discourage people
from assuming that would work, since it often says just "if FOO is set"
when describing the effects of a boolean variable. However, now this
case will result in actually setting FOO to "on", not an empty string.
2. It arranges for an "\unset" of a control variable to set the value
back to its default value, rather than becoming apparently undefined.
The control variables are also initialized that way at psql startup.
In combination, these things guarantee that a control variable always
has a displayable value that reflects what psql is actually doing.
That is a pretty substantial usability improvement.
The implementation involves adding a second type of variable hook function
that is able to replace a proposed new value (including NULL) with another
one. We could alternatively have complicated the API of the assign hook,
but this way seems better since many variables can share the same
substitution hook function.
Also document the actual behavior of these variables more fully,
including covering assorted behaviors that were there before but
never documented.
This patch also includes some minor cleanup that should have been in
511ae628f but was missed.
Patch by me, but it owes a lot to discussions with Daniel Vérité.
Discussion: https://postgr.es/m/9572.1485821620@sss.pgh.pa.us
2017-02-01 17:02:40 +01:00
|
|
|
start-up), but can be changed or unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-verbosity">
|
2003-07-28 02:14:43 +02:00
|
|
|
<term><varname>VERBOSITY</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This variable can be set to the values <literal>default</literal>,
|
2019-04-04 23:22:02 +02:00
|
|
|
<literal>verbose</literal>, <literal>terse</literal>,
|
|
|
|
or <literal>sqlstate</literal> to control the verbosity of error
|
|
|
|
reports.
|
2017-10-09 03:44:17 +02:00
|
|
|
(See also <command>\errverbose</command>, for use when you want a verbose
|
2016-04-03 18:29:55 +02:00
|
|
|
version of the error you just got.)
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2003-06-28 02:12:40 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-variables-version">
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
<term><varname>VERSION</varname></term>
|
2017-09-05 16:51:36 +02:00
|
|
|
<term><varname>VERSION_NAME</varname></term>
|
|
|
|
<term><varname>VERSION_NUM</varname></term>
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-09-05 16:51:36 +02:00
|
|
|
These variables are set at program start-up to reflect
|
2017-10-09 03:44:17 +02:00
|
|
|
<application>psql</application>'s version, respectively as a verbose string,
|
|
|
|
a short string (e.g., <literal>9.6.2</literal>, <literal>10.1</literal>,
|
|
|
|
or <literal>11beta1</literal>), and a number (e.g., <literal>90602</literal>
|
|
|
|
or <literal>100001</literal>). They can be changed or unset.
|
Make psql reject attempts to set special variables to invalid values.
Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable. This was agreed to be a not particularly good idea. With
this patch, invalid values result in an error message and no change in
state.
(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)
To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value. Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.
In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.
Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me
Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
2017-01-30 22:37:15 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
</variablelist>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect3>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<refsect3 id="app-psql-interpolation" xreflabel="SQL Interpolation">
|
|
|
|
<title><acronym>SQL</acronym> Interpolation</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<para>
|
2011-08-26 19:52:23 +02:00
|
|
|
A key feature of <application>psql</application>
|
2002-06-20 18:00:44 +02:00
|
|
|
variables is that you can substitute (<quote>interpolate</quote>)
|
2011-08-26 19:52:23 +02:00
|
|
|
them into regular <acronym>SQL</acronym> statements, as well as the
|
|
|
|
arguments of meta-commands. Furthermore,
|
|
|
|
<application>psql</application> 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
|
|
|
|
(<literal>:</literal>). For example,
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=> <userinput>\set foo 'my_table'</userinput>
|
|
|
|
testdb=> <userinput>SELECT * FROM :foo;</userinput>
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
2011-08-26 19:52:23 +02:00
|
|
|
would query the table <literal>my_table</literal>. Note that this
|
2010-01-29 18:44:12 +01:00
|
|
|
may be unsafe: the value of the variable is copied literally, so it can
|
2011-08-26 19:52:23 +02:00
|
|
|
contain unbalanced quotes, or even backslash commands. You must make sure
|
2010-01-29 18:44:12 +01:00
|
|
|
that it makes sense where you put it.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When a value is to be used as an SQL literal or identifier, it is
|
2011-08-26 19:52:23 +02:00
|
|
|
safest to arrange for it to be quoted. To quote the value of
|
2010-01-29 18:44:12 +01:00
|
|
|
a variable as an SQL literal, write a colon followed by the variable
|
2011-08-26 19:52:23 +02:00
|
|
|
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:
|
2010-01-29 18:44:12 +01:00
|
|
|
<programlisting>
|
|
|
|
testdb=> <userinput>\set foo 'my_table'</userinput>
|
|
|
|
testdb=> <userinput>SELECT * FROM :"foo";</userinput>
|
|
|
|
</programlisting>
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2011-08-26 19:52:23 +02:00
|
|
|
Variable interpolation will not be performed within quoted
|
|
|
|
<acronym>SQL</acronym> literals and identifiers. Therefore, a
|
2017-10-09 03:44:17 +02:00
|
|
|
construction such as <literal>':foo'</literal> doesn't work to produce a quoted
|
2011-08-26 19:52:23 +02:00
|
|
|
literal from a variable's value (and it would be unsafe if it did work,
|
|
|
|
since it wouldn't correctly handle quotes embedded in the value).
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
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's
|
|
|
|
value as a quoted string:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2010-01-29 18:44:12 +01:00
|
|
|
testdb=> <userinput>\set content `cat my_file.txt`</userinput>
|
|
|
|
testdb=> <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
|
2006-06-01 00:34:35 +02:00
|
|
|
</programlisting>
|
2010-08-17 06:37:21 +02:00
|
|
|
(Note that this still won't work if <filename>my_file.txt</filename> contains NUL bytes.
|
2012-06-07 23:06:20 +02:00
|
|
|
<application>psql</application> does not support embedded NUL bytes in variable values.)
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
2000-01-14 23:18:03 +01:00
|
|
|
<para>
|
2010-01-29 18:44:12 +01:00
|
|
|
Since colons can legally appear in SQL commands, an apparent attempt
|
2011-08-26 19:52:23 +02:00
|
|
|
at interpolation (that is, <literal>:name</literal>,
|
2010-01-29 18:44:12 +01:00
|
|
|
<literal>:'name'</literal>, or <literal>:"name"</literal>) is not
|
2011-08-26 19:52:23 +02:00
|
|
|
replaced unless the named variable is currently set. In any case, you
|
2010-01-29 18:44:12 +01:00
|
|
|
can escape a colon with a backslash to protect it from substitution.
|
2011-08-26 19:52:23 +02:00
|
|
|
</para>
|
|
|
|
|
2017-09-22 01:02:23 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>:{?<replaceable>name</replaceable>}</literal> special syntax returns TRUE
|
2017-09-22 01:02:23 +02:00
|
|
|
or FALSE depending on whether the variable exists or not, and is thus
|
|
|
|
always substituted, unless the colon is backslash-escaped.
|
|
|
|
</para>
|
|
|
|
|
2011-08-26 19:52:23 +02:00
|
|
|
<para>
|
|
|
|
The colon syntax for variables is standard <acronym>SQL</acronym> for
|
2003-03-24 15:32:51 +01:00
|
|
|
embedded query languages, such as <application>ECPG</application>.
|
2011-08-26 19:52:23 +02:00
|
|
|
The colon syntaxes for array slices and type casts are
|
|
|
|
<productname>PostgreSQL</productname> extensions, which can sometimes
|
|
|
|
conflict with the standard usage. The colon-quote syntax for escaping a
|
|
|
|
variable's value as an SQL literal or identifier is a
|
|
|
|
<application>psql</application> extension.
|
2000-01-14 23:18:03 +01:00
|
|
|
</para>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect3>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<refsect3 id="app-psql-prompting" xreflabel="Prompting">
|
|
|
|
<title>Prompting</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The prompts <application>psql</application> issues can be customized
|
2002-09-21 20:32:54 +02:00
|
|
|
to your preference. The three variables <varname>PROMPT1</varname>,
|
|
|
|
<varname>PROMPT2</varname>, and <varname>PROMPT3</varname> contain strings
|
2002-06-20 18:00:44 +02:00
|
|
|
and special escape sequences that describe the appearance of the
|
|
|
|
prompt. Prompt 1 is the normal prompt that is issued when
|
2003-03-24 15:32:51 +01:00
|
|
|
<application>psql</application> requests a new command. Prompt 2 is
|
2016-06-19 19:11:40 +02:00
|
|
|
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 <acronym>SQL</acronym>
|
|
|
|
<command>COPY FROM STDIN</command> command and you need to type in
|
|
|
|
a row value on the terminal.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2003-06-28 02:12:40 +02:00
|
|
|
The value of the selected prompt variable is printed literally,
|
2003-03-24 15:32:51 +01:00
|
|
|
except where a percent sign (<literal>%</literal>) is encountered.
|
2002-06-20 18:00:44 +02:00
|
|
|
Depending on the next character, certain other text is substituted
|
|
|
|
instead. Defined substitutions are:
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<variablelist>
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-m-uc">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%M</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
2001-05-06 19:21:11 +02:00
|
|
|
<para>
|
2002-03-22 20:20:45 +01:00
|
|
|
The full host name (with domain name) of the database server,
|
2002-06-20 18:00:44 +02:00
|
|
|
or <literal>[local]</literal> if the connection is over a Unix
|
|
|
|
domain socket, or
|
2008-07-03 05:37:17 +02:00
|
|
|
<literal>[local:<replaceable>/dir/name</replaceable>]</literal>,
|
2005-01-23 00:22:19 +01:00
|
|
|
if the Unix domain socket is not at the compiled in default
|
2001-05-06 19:21:11 +02:00
|
|
|
location.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-m-lc">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%m</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
2001-05-06 19:21:11 +02:00
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
The host name of the database server, truncated at the
|
2002-06-20 18:00:44 +02:00
|
|
|
first dot, or <literal>[local]</literal> if the connection is
|
|
|
|
over a Unix domain socket.
|
2001-05-06 19:21:11 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-gt">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%></literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem><para>The port number at which the database server is listening.</para></listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-n">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%n</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
2003-09-04 00:05:09 +02:00
|
|
|
<para>
|
|
|
|
The database session user name. (The expansion of this
|
|
|
|
value might change during a database session as the result
|
|
|
|
of the command <command>SET SESSION
|
|
|
|
AUTHORIZATION</command>.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-slash">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%/</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem><para>The name of the current database.</para></listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-tilde">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%~</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem><para>Like <literal>%/</literal>, but the output is <literal>~</literal>
|
2000-01-19 00:30:24 +01:00
|
|
|
(tilde) if the database is your default database.</para></listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-numbersign">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%#</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
2003-09-04 00:05:09 +02:00
|
|
|
<para>
|
|
|
|
If the session user is a database superuser, then a
|
|
|
|
<literal>#</literal>, otherwise a <literal>></literal>.
|
|
|
|
(The expansion of this value might change during a database
|
|
|
|
session as the result of the command <command>SET SESSION
|
|
|
|
AUTHORIZATION</command>.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-p">
|
2016-07-13 00:10:16 +02:00
|
|
|
<term><literal>%p</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>The process ID of the backend currently connected to.</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-r">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%R</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2016-06-19 19:11:40 +02:00
|
|
|
In prompt 1 normally <literal>=</literal>,
|
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The control
structure feature per se is complete, but the boolean expressions
understood by \if and \elif are pretty primitive; basically, after
variable substitution and backtick expansion, the result has to be
"true" or "false" or one of the other standard spellings of a boolean
value. But that's enough for many purposes, since you can always
do the heavy lifting on the server side; and we can extend it later.
Along the way, pay down some of the technical debt that had built up
around psql/command.c:
* Refactor exec_command() into a function per command, instead of
being a 1500-line monstrosity. This makes the file noticeably longer
because of repetitive function header/trailer overhead, but it seems
much more readable.
* Teach psql_get_variable() and psqlscanslash.l to suppress variable
substitution and backtick expansion on the basis of the conditional
stack state, thereby allowing removal of the OT_NO_EVAL kluge.
* Fix the no-doubt-once-expedient hack of sometimes silently substituting
mainloop.c's previous_buf for query_buf when calling HandleSlashCmds.
(It's a bit remarkable that commands like \r worked at all with that.)
Recall of a previous query is now done explicitly in the slash commands
where that should happen.
Corey Huinker, reviewed by Fabien Coelho, further hacking by me
Discussion: https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com
2017-03-30 18:59:11 +02:00
|
|
|
but <literal>@</literal> if the session is in an inactive branch of a
|
|
|
|
conditional block, or <literal>^</literal> if in single-line mode,
|
2016-06-19 19:11:40 +02:00
|
|
|
or <literal>!</literal> if the session is disconnected from the
|
|
|
|
database (which can happen if <command>\connect</command> fails).
|
|
|
|
In prompt 2 <literal>%R</literal> is replaced by a character that
|
|
|
|
depends on why <application>psql</application> expects more input:
|
|
|
|
<literal>-</literal> if the command simply wasn't terminated yet,
|
|
|
|
but <literal>*</literal> if there is an unfinished
|
|
|
|
<literal>/* ... */</literal> 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 <literal>(</literal> if there is an unmatched left parenthesis.
|
|
|
|
In prompt 3 <literal>%R</literal> doesn't produce anything.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2003-06-28 02:12:40 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-x">
|
2003-10-04 03:04:46 +02:00
|
|
|
<term><literal>%x</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Transaction status: an empty string when not in a transaction
|
2017-10-09 03:44:17 +02:00
|
|
|
block, or <literal>*</literal> when in a transaction block, or
|
|
|
|
<literal>!</literal> when in a failed transaction block, or <literal>?</literal>
|
2004-06-18 08:14:31 +02:00
|
|
|
when the transaction state is indeterminate (for example, because
|
|
|
|
there is no connection).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-l">
|
2014-09-02 13:05:48 +02:00
|
|
|
<term><literal>%l</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The line number inside the current statement, starting from <literal>1</literal>.
|
2014-09-02 13:05:48 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-digits">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%</literal><replaceable class="parameter">digits</replaceable></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-05-30 17:24:23 +02:00
|
|
|
The character with the indicated octal code is substituted.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-name">
|
2000-02-08 00:10:11 +01:00
|
|
|
<term><literal>%:</literal><replaceable class="parameter">name</replaceable><literal>:</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The value of the <application>psql</application> variable
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<replaceable class="parameter">name</replaceable>. See
|
|
|
|
<xref linkend="app-psql-variables"/>, above, for details.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-command">
|
1999-11-04 23:07:57 +01:00
|
|
|
<term><literal>%`</literal><replaceable class="parameter">command</replaceable><literal>`</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The output of <replaceable
|
|
|
|
class="parameter">command</replaceable>, similar to ordinary
|
|
|
|
<quote>back-tick</quote> substitution.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-square-brackets">
|
2004-01-20 20:49:34 +01:00
|
|
|
<term><literal>%[</literal> ... <literal>%]</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
2004-01-20 20:49:34 +01:00
|
|
|
<para>
|
Update reference documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 00:26:05 +01:00
|
|
|
Prompts can contain terminal control characters which, for
|
2004-01-20 20:49:34 +01:00
|
|
|
example, change the color, background, or style of the prompt
|
|
|
|
text, or change the title of the terminal window. In order for
|
2004-12-13 19:05:10 +01:00
|
|
|
the line editing features of <application>Readline</application> to work properly, these
|
2004-01-20 20:49:34 +01:00
|
|
|
non-printing control characters must be designated as invisible
|
|
|
|
by surrounding them with <literal>%[</literal> and
|
Update reference documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 00:26:05 +01:00
|
|
|
<literal>%]</literal>. Multiple pairs of these can occur within
|
2007-02-01 01:28:19 +01:00
|
|
|
the prompt. For example:
|
2004-01-20 20:49:34 +01:00
|
|
|
<programlisting>
|
2006-10-03 23:14:46 +02:00
|
|
|
testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
|
2004-01-20 20:49:34 +01:00
|
|
|
</programlisting>
|
|
|
|
results in a boldfaced (<literal>1;</literal>) yellow-on-black
|
|
|
|
(<literal>33;40</literal>) prompt on VT100-compatible, color-capable
|
2004-06-18 08:14:31 +02:00
|
|
|
terminals.
|
|
|
|
</para>
|
2004-01-20 20:49:34 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-prompting-w">
|
2019-11-19 03:17:15 +01:00
|
|
|
<term><literal>%w</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Whitespace of the same width as the most recent output of
|
|
|
|
<varname>PROMPT1</varname>. This can be used as a
|
|
|
|
<varname>PROMPT2</varname> setting, so that multi-line statements are
|
|
|
|
aligned with the first line, but there is no visible secondary prompt.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
</variablelist>
|
|
|
|
|
2002-06-20 18:00:44 +02:00
|
|
|
To insert a percent sign into your prompt, write
|
2003-06-28 02:12:40 +02:00
|
|
|
<literal>%%</literal>. The default prompts are
|
2020-02-12 05:31:14 +01:00
|
|
|
<literal>'%/%R%x%# '</literal> for prompts 1 and 2, and
|
2002-06-20 18:00:44 +02:00
|
|
|
<literal>'>> '</literal> for prompt 3.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
2000-01-14 23:18:03 +01:00
|
|
|
<note>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
This feature was shamelessly plagiarized from
|
|
|
|
<application>tcsh</application>.
|
2000-01-14 23:18:03 +01:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect3>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
<refsect3 id="app-psql-readline">
|
2002-09-21 20:32:54 +02:00
|
|
|
<title>Command-Line Editing</title>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary>Readline</primary>
|
|
|
|
<secondary>in psql</secondary>
|
|
|
|
</indexterm>
|
|
|
|
<indexterm>
|
|
|
|
<primary>libedit</primary>
|
|
|
|
<secondary>in psql</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<application>psql</application> uses
|
|
|
|
the <application>Readline</application>
|
|
|
|
or <application>libedit</application> library, if available, for
|
|
|
|
convenient line editing and retrieval. The command history is
|
|
|
|
automatically saved when <application>psql</application> exits and is
|
|
|
|
reloaded when <application>psql</application> starts up. Type
|
|
|
|
up-arrow or control-P to retrieve previous lines.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
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 <literal>ins</literal> and pressing
|
|
|
|
TAB will fill in <literal>insert into </literal>. Then, typing a few
|
2022-08-19 03:00:12 +02:00
|
|
|
characters of a table or schema name and pressing <literal>TAB</literal>
|
|
|
|
will fill in the unfinished name, or offer a menu of possible completions
|
|
|
|
when there's more than one. (Depending on the library in use, you may need to
|
|
|
|
press <literal>TAB</literal> more than once to get a menu.)
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
</para>
|
|
|
|
|
2000-01-14 23:18:03 +01:00
|
|
|
<para>
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
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 <command>BEGIN</command>
|
|
|
|
it will be too late to issue <command>SET TRANSACTION ISOLATION
|
|
|
|
LEVEL</command> 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
|
2002-06-20 18:00:44 +02:00
|
|
|
<filename>.inputrc</filename> in your home directory:
|
2000-02-08 00:10:11 +01:00
|
|
|
<programlisting>
|
|
|
|
$if psql
|
|
|
|
set disable-completion on
|
|
|
|
$endif
|
|
|
|
</programlisting>
|
2002-06-20 18:00:44 +02:00
|
|
|
(This is not a <application>psql</application> but a
|
2003-03-24 15:32:51 +01:00
|
|
|
<application>Readline</application> feature. Read its documentation
|
2002-06-20 18:00:44 +02:00
|
|
|
for further details.)
|
2000-01-14 23:18:03 +01:00
|
|
|
</para>
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
The <option>-n</option> (<option>--no-readline</option>) command line
|
|
|
|
option can also be useful to disable use
|
|
|
|
of <application>Readline</application> for a single run
|
|
|
|
of <application>psql</application>. 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
|
2022-08-19 03:00:12 +02:00
|
|
|
text that contains <literal>TAB</literal> characters.
|
psql: improve tab-complete's handling of variant SQL names.
This patch improves tab completion's ability to deal with
valid variant spellings of SQL identifiers. Notably:
* Unquoted upper-case identifiers are now downcased as the backend
would do, allowing them to be completed correctly.
* Tab completion can now match identifiers that are quoted even
though they don't need to be; for example "f<TAB> now completes
to "foo" if that's the only available name. Previously, only
names that require quotes would be offered.
* Schema-qualified identifiers are now supported where SQL syntax
allows it; many lesser-used completion rules neglected this.
* Completion operations that refer back to some previously-typed
name (for example, to complete names of columns belonging to a
previously-mentioned table) now allow variant spellings of the
previous name too.
In addition, performance of tab completion queries has been
improved for databases containing many objects, although
you'd only be likely to notice with a heavily-loaded server.
Authors of future tab-completion patches should note that this
commit changes many details about how tab completion queries
must be written:
* Tab completion queries now deal in raw object names; do not
use quote_ident().
* The name-matching restriction in a query must now be written
as "outputcol LIKE '%s'", not "substring(outputcol,1,%d)='%s'".
* The SchemaQuery mechanism has been extended so that it can
handle queries that refer back to a previous name. Most completion
queries that do that should be converted to SchemaQuery form.
Only consider using a literal query if the previous name can
never be schema-qualified. Don't use a literal query if the
name-to-be-completed can validly be schema-qualified, either.
* Use set_completion_reference() to specify which word is the previous
name to consider, for either a SchemaQuery or a literal query.
* If you want to offer some keywords in addition to a query result
(for example, offer COLUMN in addition to column names after
"ALTER TABLE t RENAME"), do not use the old hack of tacking the
keywords on with UNION. Instead use the new QUERY_PLUS macros
to write such keywords separately from the query proper. The
"addon" macro arguments that used to be used for this purpose
are gone.
* If your query returns something that's not a SQL identifier
(such as an attribute number or enum label), use the new
QUERY_VERBATIM macros to prevent the result from incorrectly
getting double-quoted. You may still need to use quote_literal
in such a query, too.
Tom Lane and Haiying Tang
Discussion: https://postgr.es/m/a63cbd45e3884cf9b3961c2a6a95dcb7@G08CNEXMBPEKD05.g08.fujitsu.local
2022-01-30 19:33:23 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect3>
|
2000-01-14 23:18:03 +01:00
|
|
|
</refsect2>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<refsect1 id="app-psql-environment" xreflabel="Environment">
|
|
|
|
<title>Environment</title>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
|
|
|
<variablelist>
|
2008-05-08 19:04:26 +02:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-columns">
|
2008-05-08 19:04:26 +02:00
|
|
|
<term><envar>COLUMNS</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If <literal>\pset columns</literal> is zero, controls the
|
|
|
|
width for the <literal>wrapped</literal> format and width for determining
|
2011-11-12 16:03:10 +01:00
|
|
|
if wide output requires the pager or should be switched to the
|
|
|
|
vertical format in expanded auto mode.
|
2008-05-08 19:04:26 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-pgdatabase">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><envar>PGDATABASE</envar></term>
|
|
|
|
<term><envar>PGHOST</envar></term>
|
|
|
|
<term><envar>PGPORT</envar></term>
|
|
|
|
<term><envar>PGUSER</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
Default connection parameters (see <xref linkend="libpq-envars"/>).
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-pg-color">
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
<term><envar>PG_COLOR</envar></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-03-09 02:53:22 +01:00
|
|
|
Specifies whether to use color in diagnostic messages. Possible values
|
|
|
|
are <literal>always</literal>, <literal>auto</literal> and
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
<literal>never</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-psql-editor">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><envar>PSQL_EDITOR</envar></term>
|
|
|
|
<term><envar>EDITOR</envar></term>
|
|
|
|
<term><envar>VISUAL</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-07-03 21:48:18 +02:00
|
|
|
Editor used by the <command>\e</command>, <command>\ef</command>,
|
|
|
|
and <command>\ev</command> commands.
|
|
|
|
These variables are examined in the order listed;
|
|
|
|
the first that is set is used.
|
2017-09-05 18:02:06 +02:00
|
|
|
If none of them is set, the default is to use <filename>vi</filename>
|
|
|
|
on Unix systems or <filename>notepad.exe</filename> on Windows systems.
|
2011-07-23 23:25:29 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-psql-editor-linenumber-arg">
|
2011-07-23 23:25:29 +02:00
|
|
|
<term><envar>PSQL_EDITOR_LINENUMBER_ARG</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-07-03 21:48:18 +02:00
|
|
|
When <command>\e</command>, <command>\ef</command>, or
|
|
|
|
<command>\ev</command> is used
|
2011-07-23 23:25:29 +02:00
|
|
|
with a line number argument, this variable specifies the
|
|
|
|
command-line argument used to pass the starting line number to
|
2017-10-09 03:44:17 +02:00
|
|
|
the user's editor. For editors such as <productname>Emacs</productname> or
|
|
|
|
<productname>vi</productname>, this is a plus sign. Include a trailing
|
2011-07-23 23:25:29 +02:00
|
|
|
space in the value of the variable if there needs to be space
|
|
|
|
between the option name and the line number. Examples:
|
|
|
|
<programlisting>
|
|
|
|
PSQL_EDITOR_LINENUMBER_ARG='+'
|
|
|
|
PSQL_EDITOR_LINENUMBER_ARG='--line '
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The default is <literal>+</literal> on Unix systems
|
|
|
|
(corresponding to the default editor <filename>vi</filename>,
|
|
|
|
and useful for many other common editors); but there is no
|
|
|
|
default on Windows systems.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-psql-history">
|
2012-03-03 22:39:26 +01:00
|
|
|
<term><envar>PSQL_HISTORY</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-06-07 23:06:20 +02:00
|
|
|
Alternative location for the command history file. Tilde (<literal>~</literal>) expansion is performed.
|
2012-03-03 22:39:26 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-pager">
|
2017-09-05 18:02:06 +02:00
|
|
|
<term><envar>PSQL_PAGER</envar></term>
|
|
|
|
<term><envar>PAGER</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If a query's results do not fit on the screen, they are piped
|
|
|
|
through this command. Typical values are <literal>more</literal>
|
|
|
|
or <literal>less</literal>.
|
|
|
|
Use of the pager can be disabled by setting <envar>PSQL_PAGER</envar>
|
|
|
|
or <envar>PAGER</envar> to an empty string, or by adjusting the
|
|
|
|
pager-related options of the <command>\pset</command> command.
|
|
|
|
These variables are examined in the order listed;
|
|
|
|
the first that is set is used.
|
2023-05-12 22:11:14 +02:00
|
|
|
If neither of them is set, the default is to use <literal>more</literal> on most
|
2017-10-09 03:44:17 +02:00
|
|
|
platforms, but <literal>less</literal> on Cygwin.
|
2017-09-05 18:02:06 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-psql-watch-pager">
|
2021-07-13 01:13:48 +02:00
|
|
|
<term><envar>PSQL_WATCH_PAGER</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When a query is executed repeatedly with the <command>\watch</command>
|
|
|
|
command, a pager is not used by default. This behavior can be changed
|
|
|
|
by setting <envar>PSQL_WATCH_PAGER</envar> to a pager command, on Unix
|
|
|
|
systems. The <literal>pspg</literal> pager (not part of
|
|
|
|
<productname>PostgreSQL</productname> but available in many open source
|
|
|
|
software distributions) can display the output of
|
|
|
|
<command>\watch</command> if started with the option
|
|
|
|
<literal>--stream</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-psqlrc">
|
2012-03-03 22:39:26 +01:00
|
|
|
<term><envar>PSQLRC</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-06-07 23:06:20 +02:00
|
|
|
Alternative location of the user's <filename>.psqlrc</filename> file. Tilde (<literal>~</literal>) expansion is performed.
|
2012-03-03 22:39:26 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-shell">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><envar>SHELL</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Command executed by the <command>\!</command> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-environment-tmpdir">
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><envar>TMPDIR</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Directory for storing temporary files. The default is
|
|
|
|
<filename>/tmp</filename>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2006-11-21 18:01:58 +01:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This utility, like most other <productname>PostgreSQL</productname> utilities,
|
|
|
|
also uses the environment variables supported by <application>libpq</application>
|
2017-11-23 15:39:47 +01:00
|
|
|
(see <xref linkend="libpq-envars"/>).
|
2006-11-21 18:01:58 +01:00
|
|
|
</para>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Files</title>
|
|
|
|
|
2014-01-15 01:27:57 +01:00
|
|
|
<variablelist>
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-files-psqlrc">
|
2014-01-15 01:27:57 +01:00
|
|
|
<term><filename>psqlrc</filename> and <filename>~/.psqlrc</filename></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-12-08 20:04:08 +01:00
|
|
|
Unless it is passed an <option>-X</option> option,
|
2014-01-15 01:27:57 +01:00
|
|
|
<application>psql</application> attempts to read and execute commands
|
|
|
|
from the system-wide startup file (<filename>psqlrc</filename>) and then
|
|
|
|
the user's personal startup file (<filename>~/.psqlrc</filename>), 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 <command>\set</command> and <command>SET</command>
|
|
|
|
commands.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2012-03-03 22:39:26 +01:00
|
|
|
<para>
|
2022-09-09 19:50:42 +02:00
|
|
|
The system-wide startup file is named <filename>psqlrc</filename>.
|
|
|
|
By default it is
|
2017-10-09 03:44:17 +02:00
|
|
|
sought in the installation's <quote>system configuration</quote> directory,
|
2014-01-15 01:27:57 +01:00
|
|
|
which is most reliably identified by running <literal>pg_config
|
2022-09-09 19:50:42 +02:00
|
|
|
--sysconfdir</literal>.
|
|
|
|
Typically this directory will be <filename>../etc/</filename>
|
2014-01-15 01:27:57 +01:00
|
|
|
relative to the directory containing
|
2022-09-09 19:50:42 +02:00
|
|
|
the <productname>PostgreSQL</productname> executables.
|
|
|
|
The directory to look in can be set explicitly via
|
|
|
|
the <envar>PGSYSCONFDIR</envar> environment variable.
|
2014-01-15 01:27:57 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The user's personal startup file is named <filename>.psqlrc</filename>
|
2022-09-09 19:50:42 +02:00
|
|
|
and is sought in the invoking user's home directory.
|
|
|
|
On Windows the personal startup file is instead named
|
2014-01-15 01:27:57 +01:00
|
|
|
<filename>%APPDATA%\postgresql\psqlrc.conf</filename>.
|
2022-09-09 19:50:42 +02:00
|
|
|
In either case, this default file path can be overridden by setting
|
2014-01-15 01:27:57 +01:00
|
|
|
the <envar>PSQLRC</envar> environment variable.
|
2012-03-03 22:39:26 +01:00
|
|
|
</para>
|
2005-01-06 19:29:11 +01:00
|
|
|
<para>
|
2014-01-15 01:27:57 +01:00
|
|
|
Both the system-wide startup file and the user's personal startup file
|
|
|
|
can be made <application>psql</application>-version-specific
|
2005-01-06 19:29:11 +01:00
|
|
|
by appending a dash and the <productname>PostgreSQL</productname>
|
2022-09-09 19:50:42 +02:00
|
|
|
major or minor release identifier to the file name,
|
|
|
|
for example <filename>~/.psqlrc-&majorversion;</filename> or
|
|
|
|
<filename>~/.psqlrc-&version;</filename>.
|
|
|
|
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.
|
2005-01-06 19:29:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2014-01-15 01:27:57 +01:00
|
|
|
</varlistentry>
|
2005-01-06 19:29:11 +01:00
|
|
|
|
2023-01-09 21:08:24 +01:00
|
|
|
<varlistentry id="app-psql-files-psql-history">
|
2014-01-15 01:27:57 +01:00
|
|
|
<term><filename>.psql_history</filename></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The command-line history is stored in the file
|
2005-01-06 19:29:11 +01:00
|
|
|
<filename>~/.psql_history</filename>, or
|
2005-01-06 22:20:44 +01:00
|
|
|
<filename>%APPDATA%\postgresql\psql_history</filename> on Windows.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2012-03-03 22:39:26 +01:00
|
|
|
<para>
|
2014-01-15 01:27:57 +01:00
|
|
|
The location of the history file can be set explicitly via
|
2017-10-09 03:44:17 +02:00
|
|
|
the <varname>HISTFILE</varname> <application>psql</application> variable or
|
2014-01-15 01:27:57 +01:00
|
|
|
the <envar>PSQL_HISTORY</envar> environment variable.
|
2012-03-03 22:39:26 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
2014-01-15 01:27:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
2012-09-01 05:28:14 +02:00
|
|
|
<para><application>psql</application> works best with servers of the same
|
|
|
|
or an older major version. Backslash commands are particularly likely
|
2017-10-09 03:44:17 +02:00
|
|
|
to fail if the server is of a newer version than <application>psql</application>
|
|
|
|
itself. However, backslash commands of the <literal>\d</literal> family should
|
2022-05-31 18:18:27 +02:00
|
|
|
work with servers of versions back to 9.2, though not necessarily with
|
2017-10-09 03:44:17 +02:00
|
|
|
servers newer than <application>psql</application> itself. The general
|
2012-09-01 05:28:14 +02:00
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If you want to use <application>psql</application> to connect to several
|
|
|
|
servers of different major versions, it is recommended that you use the
|
|
|
|
newest version of <application>psql</application>. Alternatively, you
|
2015-12-13 20:52:07 +01:00
|
|
|
can keep around a copy of <application>psql</application> from each
|
|
|
|
major version and be sure to use the version that matches the
|
2012-09-01 05:28:14 +02:00
|
|
|
respective server. But in practice, this additional complication should
|
|
|
|
not be necessary.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2015-12-08 20:04:08 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2015-12-13 20:52:07 +01:00
|
|
|
Before <productname>PostgreSQL</productname> 9.6,
|
|
|
|
the <option>-c</option> option implied <option>-X</option>
|
2017-10-09 03:44:17 +02:00
|
|
|
(<option>--no-psqlrc</option>); this is no longer the case.
|
2015-12-13 20:52:07 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Before <productname>PostgreSQL</productname> 8.4,
|
|
|
|
<application>psql</application> allowed the
|
|
|
|
first argument of a single-letter backslash command to start
|
|
|
|
directly after the command, without intervening whitespace.
|
|
|
|
Now, some whitespace is required.
|
2015-12-08 20:04:08 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</itemizedlist>
|
|
|
|
</refsect1>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
|
2004-12-27 21:13:48 +01:00
|
|
|
<refsect1>
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>Notes for Windows Users</title>
|
2004-12-27 21:13:48 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
<application>psql</application> is built as a <quote>console
|
2017-10-09 03:44:17 +02:00
|
|
|
application</quote>. Since the Windows console windows use a different
|
2004-12-27 21:13:48 +01:00
|
|
|
encoding than the rest of the system, you must take special care
|
|
|
|
when using 8-bit characters within <application>psql</application>.
|
|
|
|
If <application>psql</application> detects a problematic
|
|
|
|
console code page, it will warn you at startup. To change the
|
|
|
|
console code page, two things are necessary:
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Set the code page by entering <userinput>cmd.exe /c chcp
|
|
|
|
1252</userinput>. (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 <filename>/etc/profile</filename>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Set the console font to <literal>Lucida Console</literal>, because the
|
2004-12-27 21:13:48 +01:00
|
|
|
raster font does not work with the ANSI code page.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2011-08-07 09:49:45 +02:00
|
|
|
</itemizedlist></para>
|
2004-12-27 21:13:48 +01:00
|
|
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<refsect1 id="app-psql-examples" xreflabel="Examples">
|
|
|
|
<title>Examples</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
The first example shows how to spread a command over several lines of
|
2002-06-20 18:00:44 +02:00
|
|
|
input. Notice the changing prompt:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=> <userinput>CREATE TABLE my_table (</userinput>
|
2005-01-23 00:22:19 +01:00
|
|
|
testdb(> <userinput> first integer not null default 0,</userinput>
|
|
|
|
testdb(> <userinput> second text)</userinput>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb-> <userinput>;</userinput>
|
2003-03-24 15:32:51 +01:00
|
|
|
CREATE TABLE
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
1999-11-04 23:07:57 +01:00
|
|
|
Now look at the table definition again:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=> <userinput>\d my_table</userinput>
|
2016-11-03 17:00:00 +01:00
|
|
|
Table "public.my_table"
|
|
|
|
Column | Type | Collation | Nullable | Default
|
|
|
|
--------+---------+-----------+----------+---------
|
|
|
|
first | integer | | not null | 0
|
2022-04-20 17:04:28 +02:00
|
|
|
second | text | | |
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
2003-03-24 15:32:51 +01:00
|
|
|
Now we change the prompt to something more interesting:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
testdb=> <userinput>\set PROMPT1 '%n@%m %~%R%# '</userinput>
|
|
|
|
peter@localhost testdb=>
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
2002-06-20 18:00:44 +02:00
|
|
|
Let's assume you have filled the table with data and want to take a
|
|
|
|
look at it:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> SELECT * FROM my_table;
|
1999-11-04 23:07:57 +01:00
|
|
|
first | second
|
|
|
|
-------+--------
|
|
|
|
1 | one
|
|
|
|
2 | two
|
|
|
|
3 | three
|
|
|
|
4 | four
|
|
|
|
(4 rows)
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
2005-01-04 04:58:16 +01:00
|
|
|
You can display tables in different ways by using the
|
2002-06-20 18:00:44 +02:00
|
|
|
<command>\pset</command> command:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset border 2</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Border style is 2.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>SELECT * FROM my_table;</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
+-------+--------+
|
|
|
|
| first | second |
|
|
|
|
+-------+--------+
|
|
|
|
| 1 | one |
|
|
|
|
| 2 | two |
|
|
|
|
| 3 | three |
|
|
|
|
| 4 | four |
|
|
|
|
+-------+--------+
|
|
|
|
(4 rows)
|
|
|
|
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset border 0</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Border style is 0.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>SELECT * FROM my_table;</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
first second
|
|
|
|
----- ------
|
|
|
|
1 one
|
|
|
|
2 two
|
|
|
|
3 three
|
|
|
|
4 four
|
|
|
|
(4 rows)
|
|
|
|
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset border 1</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Border style is 1.
|
2018-11-26 21:18:55 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset format csv</userinput>
|
|
|
|
Output format is csv.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset tuples_only</userinput>
|
2018-11-26 21:18:55 +01:00
|
|
|
Tuples only is on.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>SELECT second, first FROM my_table;</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
one,1
|
|
|
|
two,2
|
|
|
|
three,3
|
|
|
|
four,4
|
2018-11-26 21:18:55 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset format unaligned</userinput>
|
|
|
|
Output format is unaligned.
|
|
|
|
peter@localhost testdb=> <userinput>\pset fieldsep '\t'</userinput>
|
|
|
|
Field separator is " ".
|
|
|
|
peter@localhost testdb=> <userinput>SELECT second, first FROM my_table;</userinput>
|
|
|
|
one 1
|
|
|
|
two 2
|
|
|
|
three 3
|
|
|
|
four 4
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
</programlisting>
|
1999-11-04 23:07:57 +01:00
|
|
|
Alternatively, use the short commands:
|
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\a \t \x</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Output format is aligned.
|
|
|
|
Tuples only is off.
|
|
|
|
Expanded display is on.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>SELECT * FROM my_table;</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
-[ RECORD 1 ]-
|
|
|
|
first | 1
|
|
|
|
second | one
|
|
|
|
-[ RECORD 2 ]-
|
|
|
|
first | 2
|
|
|
|
second | two
|
|
|
|
-[ RECORD 3 ]-
|
|
|
|
first | 3
|
|
|
|
second | three
|
|
|
|
-[ RECORD 4 ]-
|
|
|
|
first | 4
|
|
|
|
second | four
|
2020-04-07 23:46:29 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Also, these output format options can be set for just one query by using
|
|
|
|
<literal>\g</literal>:
|
|
|
|
<programlisting>
|
|
|
|
peter@localhost testdb=> <userinput>SELECT * FROM my_table</userinput>
|
|
|
|
peter@localhost testdb-> <userinput>\g (format=aligned tuples_only=off expanded=on)</userinput>
|
|
|
|
-[ RECORD 1 ]-
|
|
|
|
first | 1
|
|
|
|
second | one
|
|
|
|
-[ RECORD 2 ]-
|
|
|
|
first | 2
|
|
|
|
second | two
|
|
|
|
-[ RECORD 3 ]-
|
|
|
|
first | 3
|
|
|
|
second | three
|
|
|
|
-[ RECORD 4 ]-
|
|
|
|
first | 4
|
|
|
|
second | four
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2021-04-08 05:02:16 +02:00
|
|
|
<para>
|
|
|
|
Here is an example of using the <command>\df</command> command to
|
|
|
|
find only functions with names matching <literal>int*pl</literal>
|
|
|
|
and whose second argument is of type <type>bigint</type>:
|
|
|
|
<programlisting>
|
|
|
|
testdb=> <userinput>\df int*pl * bigint</userinput>
|
|
|
|
List of functions
|
|
|
|
Schema | Name | Result data type | Argument data types | Type
|
|
|
|
------------+---------+------------------+---------------------+------
|
|
|
|
pg_catalog | int28pl | bigint | smallint, bigint | func
|
|
|
|
pg_catalog | int48pl | bigint | integer, bigint | func
|
|
|
|
pg_catalog | int8pl | bigint | bigint, bigint | func
|
|
|
|
(3 rows)
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
2020-04-07 23:46:29 +02:00
|
|
|
<para>
|
2016-04-09 01:23:18 +02:00
|
|
|
When suitable, query results can be shown in a crosstab representation
|
2016-07-29 04:46:15 +02:00
|
|
|
with the <command>\crosstabview</command> command:
|
2016-04-09 01:23:18 +02:00
|
|
|
<programlisting>
|
|
|
|
testdb=> <userinput>SELECT first, second, first > 2 AS gt2 FROM my_table;</userinput>
|
2022-04-20 17:04:28 +02:00
|
|
|
first | second | gt2
|
2016-04-09 01:23:18 +02:00
|
|
|
-------+--------+-----
|
|
|
|
1 | one | f
|
|
|
|
2 | two | f
|
|
|
|
3 | three | t
|
|
|
|
4 | four | t
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
testdb=> <userinput>\crosstabview first second</userinput>
|
2022-04-20 17:04:28 +02:00
|
|
|
first | one | two | three | four
|
2016-04-09 01:23:18 +02:00
|
|
|
-------+-----+-----+-------+------
|
2022-04-20 17:04:28 +02:00
|
|
|
1 | f | | |
|
|
|
|
2 | | f | |
|
|
|
|
3 | | | t |
|
2016-04-09 01:23:18 +02:00
|
|
|
4 | | | | t
|
|
|
|
(4 rows)
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
This second example shows a multiplication table with rows sorted in reverse
|
2016-06-03 16:13:36 +02:00
|
|
|
numerical order and columns with an independent, ascending numerical order.
|
2016-04-09 01:23:18 +02:00
|
|
|
<programlisting>
|
|
|
|
testdb=> <userinput>SELECT t1.first as "A", t2.first+100 AS "B", t1.first*(t2.first+100) as "AxB",</userinput>
|
|
|
|
testdb(> <userinput>row_number() over(order by t2.first) AS ord</userinput>
|
|
|
|
testdb(> <userinput>FROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC</userinput>
|
2016-05-06 16:39:35 +02:00
|
|
|
testdb(> <userinput>\crosstabview "A" "B" "AxB" ord</userinput>
|
2022-04-20 17:04:28 +02:00
|
|
|
A | 101 | 102 | 103 | 104
|
2016-04-09 01:23:18 +02:00
|
|
|
---+-----+-----+-----+-----
|
|
|
|
4 | 404 | 408 | 412 | 416
|
|
|
|
3 | 303 | 306 | 309 | 312
|
|
|
|
2 | 202 | 204 | 206 | 208
|
|
|
|
1 | 101 | 102 | 103 | 104
|
|
|
|
(4 rows)
|
2020-06-07 14:54:28 +02:00
|
|
|
</programlisting></para>
|
2016-04-09 01:23:18 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</refsect1>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
1998-10-15 07:47:04 +02:00
|
|
|
</refentry>
|