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
|
|
|
-->
|
|
|
|
|
1999-06-14 09:37:05 +02:00
|
|
|
<refentry id="APP-PSQL">
|
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>
|
|
|
|
|
2003-08-31 19:32:24 +02:00
|
|
|
<indexterm zone="app-psql">
|
|
|
|
<primary>psql</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
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>
|
2002-07-28 17:22:21 +02:00
|
|
|
<arg><replaceable class="parameter">dbname</replaceable>
|
2003-03-24 15:32:51 +01:00
|
|
|
<arg><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.
|
|
|
|
Alternatively, input can be from a file. In addition, it 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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect1 id="R1-APP-PSQL-3">
|
|
|
|
<title>Options</title>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-a</></term>
|
|
|
|
<term><option>--echo-all</></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-04 04:58:16 +01:00
|
|
|
Print all input lines to standard output as they are read. This is more
|
2010-02-19 04:50:03 +01:00
|
|
|
useful for script processing than interactive mode. 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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-A</></term>
|
|
|
|
<term><option>--no-align</></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Switches to unaligned output mode. (The default output mode is
|
|
|
|
otherwise aligned.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2003-03-24 15:32:51 +01:00
|
|
|
<term><option>-c <replaceable class="parameter">command</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--command=<replaceable class="parameter">command</replaceable></></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies that <application>psql</application> is to execute one
|
2003-03-24 15:32:51 +01:00
|
|
|
command string, <replaceable class="parameter">command</replaceable>,
|
2010-07-10 02:50:24 +02:00
|
|
|
and then exit. This is useful in shell scripts. Start-up files
|
|
|
|
(<filename>psqlrc</filename> and <filename>~/.psqlrc</filename>) are
|
|
|
|
ignored with this option.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
<replaceable class="parameter">command</replaceable> must be either
|
|
|
|
a command string that is completely parsable by the server (i.e.,
|
2010-02-19 04:50:03 +01:00
|
|
|
it contains no <application>psql</application>-specific features),
|
2005-01-04 04:58:16 +01:00
|
|
|
or a single backslash command. Thus you cannot mix
|
2002-07-28 17:22:21 +02:00
|
|
|
<acronym>SQL</acronym> and <application>psql</application>
|
2006-12-06 16:40:11 +01:00
|
|
|
meta-commands with this option. To achieve that, you could
|
|
|
|
pipe the string into <application>psql</application>, like
|
2006-12-06 16:47:22 +01:00
|
|
|
this: <literal>echo '\x \\ SELECT * FROM foo;' | psql</literal>.
|
2006-12-06 16:40:11 +01:00
|
|
|
(<literal>\\</> is the separator meta-command.)
|
2003-03-24 19:33:52 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2003-05-14 05:26:03 +02:00
|
|
|
If the command string contains multiple SQL commands, they are
|
|
|
|
processed in a single transaction, unless there are explicit
|
2006-10-31 02:52:31 +01:00
|
|
|
<command>BEGIN</>/<command>COMMIT</> commands included in the
|
|
|
|
string to divide it into multiple transactions. This is
|
|
|
|
different from the behavior when the same string is fed to
|
|
|
|
<application>psql</application>'s standard input.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-d <replaceable class="parameter">dbname</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--dbname=<replaceable class="parameter">dbname</replaceable></></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
|
|
|
|
argument on the command line.
|
|
|
|
</para>
|
|
|
|
<para>
|
2007-05-03 17:47:48 +02:00
|
|
|
If this parameter contains an <symbol>=</symbol> sign, it is treated as a
|
2007-02-22 00:21:12 +01:00
|
|
|
<parameter>conninfo</parameter> string. See <xref linkend="libpq-connect"> for more information.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-e</></term>
|
|
|
|
<term><option>--echo-queries</></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-E</></term>
|
|
|
|
<term><option>--echo-hidden</></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
|
2002-09-21 20:32:54 +02:00
|
|
|
setting the variable <varname>ECHO_HIDDEN</varname> from within
|
2002-07-28 17:22:21 +02:00
|
|
|
<application>psql</application>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-f <replaceable class="parameter">filename</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--file=<replaceable class="parameter">filename</replaceable></></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Use the file <replaceable class="parameter">filename</replaceable>
|
2003-03-24 15:32:51 +01:00
|
|
|
as the source of commands instead of reading commands interactively.
|
2002-07-28 17:22:21 +02:00
|
|
|
After the file is processed, <application>psql</application>
|
|
|
|
terminates. This is in many ways equivalent to the internal
|
|
|
|
command <command>\i</command>.
|
|
|
|
</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>
|
|
|
|
(hyphen), then standard input is read.
|
|
|
|
</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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-F <replaceable class="parameter">separator</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--field-separator=<replaceable class="parameter">separator</replaceable></></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-h <replaceable class="parameter">hostname</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--host=<replaceable class="parameter">hostname</replaceable></></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-H</></term>
|
|
|
|
<term><option>--html</></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Turn on <acronym>HTML</acronym> tabular output. This is
|
2002-07-28 17:22:21 +02:00
|
|
|
equivalent to <literal>\pset format html</literal> or the
|
|
|
|
<command>\H</command> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-l</></term>
|
|
|
|
<term><option>--list</></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
|
2002-07-28 17:22:21 +02:00
|
|
|
options are ignored. This is similar to the internal command
|
|
|
|
<command>\list</command>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2005-06-14 04:57:45 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-L <replaceable class="parameter">filename</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--log-file=<replaceable class="parameter">filename</replaceable></></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>
|
|
|
|
|
2009-08-11 14:02:58 +02:00
|
|
|
<varlistentry>
|
2009-08-10 04:39:04 +02:00
|
|
|
<term><option>-n</></term>
|
|
|
|
<term><option>--no-readline</></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Do not use readline for line editing and do not use the history.
|
|
|
|
This can be useful to turn off tab expansion when cutting and pasting.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-o <replaceable class="parameter">filename</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--output=<replaceable class="parameter">filename</replaceable></></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-p <replaceable class="parameter">port</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--port=<replaceable class="parameter">port</replaceable></></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-P <replaceable class="parameter">assignment</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--pset=<replaceable class="parameter">assignment</replaceable></></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
|
2010-02-19 04:50:03 +01:00
|
|
|
space. For example, to set the output format to LaTeX, 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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-q</></term>
|
|
|
|
<term><option>--quiet</></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.
|
|
|
|
Within <application>psql</application> you can also set the
|
2002-09-21 20:32:54 +02:00
|
|
|
<varname>QUIET</varname> variable to achieve the same effect.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-R <replaceable class="parameter">separator</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--record-separator=<replaceable class="parameter">separator</replaceable></></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
|
|
|
record separator for unaligned output. This is equivalent to the
|
|
|
|
<command>\pset recordsep</command> command.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-s</></term>
|
|
|
|
<term><option>--single-step</></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-S</></term>
|
|
|
|
<term><option>--single-line</></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-t</></term>
|
|
|
|
<term><option>--tuples-only</></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Turn off printing of column names and result row count footers,
|
2005-01-04 04:58:16 +01:00
|
|
|
etc. This is equivalent to the <command>\t</command> command.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-T <replaceable class="parameter">table_options</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--table-attr=<replaceable class="parameter">table_options</replaceable></></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
|
|
|
|
<command>\pset</command> for details.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-06-18 08:14:31 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-U <replaceable class="parameter">username</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--username=<replaceable class="parameter">username</replaceable></></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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-v <replaceable class="parameter">assignment</replaceable></></term>
|
2011-03-10 15:09:35 +01:00
|
|
|
<term><option>--set=<replaceable class="parameter">assignment</replaceable></></term>
|
|
|
|
<term><option>--variable=<replaceable class="parameter">assignment</replaceable></></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>
|
2002-07-28 17:22:21 +02:00
|
|
|
internal command. Note that you must separate name and value, if
|
|
|
|
any, by an equal sign on the command line. To unset a variable,
|
|
|
|
leave off the equal sign. To just set a variable without a value,
|
|
|
|
use the equal sign but leave off the value. These assignments are
|
|
|
|
done during a very early stage of start-up, so variables reserved
|
|
|
|
for internal purposes might get overwritten later.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-V</></term>
|
|
|
|
<term><option>--version</></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
|
|
|
|
2009-02-26 17:02:39 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-w</></term>
|
|
|
|
<term><option>--no-password</></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Never issue a password prompt. If the server requires password
|
|
|
|
authentication and a password is not available by other means
|
|
|
|
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>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-W</></term>
|
|
|
|
<term><option>--password</></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
|
2008-07-03 05:37:17 +02:00
|
|
|
password before connecting to a database.
|
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>
|
2007-12-11 20:57:32 +01:00
|
|
|
This option is never essential, since <application>psql</application>
|
|
|
|
will automatically prompt for a password if the server demands
|
|
|
|
password authentication. However, <application>psql</application>
|
|
|
|
will waste a connection attempt finding out that the server wants a
|
|
|
|
password. In some cases it is worth typing <option>-W</> to avoid
|
|
|
|
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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-x</></term>
|
|
|
|
<term><option>--expanded</></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-06-13 08:36:22 +02:00
|
|
|
Turn on the expanded table formatting mode. This is equivalent to the
|
|
|
|
<command>\x</command> command.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-X,</></term>
|
|
|
|
<term><option>--no-psqlrc</></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
|
|
|
|
2006-02-12 05:04:32 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-1</option></term>
|
|
|
|
<term><option>--single-transaction</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2006-02-13 22:29:08 +01:00
|
|
|
When <application>psql</application> executes a script with the
|
|
|
|
<option>-f</> option, adding this option wraps
|
|
|
|
<command>BEGIN</>/<command>COMMIT</> around the script to execute it
|
|
|
|
as a single transaction. This ensures that either all the commands
|
2008-07-03 05:37:17 +02:00
|
|
|
complete successfully, or no changes are applied.
|
2006-10-31 02:52:31 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2006-10-31 03:29:15 +01:00
|
|
|
If the script itself uses <command>BEGIN</>, <command>COMMIT</>,
|
|
|
|
or <command>ROLLBACK</>, this option will not have the desired
|
|
|
|
effects.
|
|
|
|
Also, if the script contains any command that cannot be executed
|
|
|
|
inside a transaction block, specifying this option will cause that
|
|
|
|
command (and hence the whole transaction) to fail.
|
2006-02-12 05:04:32 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><option>-?</></term>
|
|
|
|
<term><option>--help</></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Show help about <application>psql</application> command line
|
2005-01-04 04:58:16 +01:00
|
|
|
arguments, and exit.
|
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
|
2010-02-19 04:50:03 +01:00
|
|
|
finished normally, 1 if a fatal error of its own occurs (e.g. out of memory,
|
|
|
|
file not found), 2 if the connection to the server went bad
|
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
|
|
|
|
2002-07-28 17:22:21 +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
|
2010-02-19 04:50:03 +01:00
|
|
|
database, the host name and port number of the server, and what user
|
2002-07-28 17:22:21 +02:00
|
|
|
name you want to connect as. <application>psql</application> can be
|
|
|
|
told about those parameters via command line options, namely
|
|
|
|
<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
|
2004-12-29 00:17:54 +01:00
|
|
|
(or the 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
|
2004-12-29 00:17:54 +01:00
|
|
|
name, <application>psql</> will connect via a Unix-domain socket
|
|
|
|
to a server on the local host, or via TCP/IP to <literal>localhost</> on
|
|
|
|
machines that don't have Unix-domain sockets. The default port number is
|
|
|
|
determined at compile time.
|
2002-07-28 17:22:21 +02:00
|
|
|
Since the database server uses the same default, you will not have
|
|
|
|
to specify the port in most cases. The default user name is your
|
Wording cleanup for error messages. Also change can't -> cannot.
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 20:10:30 +01:00
|
|
|
Unix user name, as is the default database name. Note that you cannot
|
2002-07-28 17:22:21 +02:00
|
|
|
just connect to any database under any 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
|
|
|
|
linkend="libpq-envars">.) It is also convenient to have a
|
|
|
|
<filename>~/.pgpass</> file to avoid regularly having to type in
|
|
|
|
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
|
2008-07-03 05:37:17 +02:00
|
|
|
<parameter>conninfo</parameter> string, 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>
|
|
|
|
</programlisting>
|
2007-09-14 16:31:22 +02:00
|
|
|
This way you can also use LDAP for connection parameter lookup as
|
|
|
|
described in <xref linkend="libpq-ldap">.
|
2007-02-22 00:21:12 +01:00
|
|
|
See <xref linkend="libpq-connect"> for more information on all the
|
|
|
|
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>
|
|
|
|
If at least one of standard input or standard output are a
|
|
|
|
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
|
|
|
|
2002-07-28 17:22:21 +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
|
|
|
|
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
|
2010-04-03 09:23:02 +02:00
|
|
|
<xref linkend="SQL-LISTEN"> and
|
|
|
|
<xref linkend="SQL-NOTIFY">.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</refsect2>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2010-03-21 01:43:40 +01: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>
|
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
|
|
|
To include whitespace into an argument you can quote it with a
|
2002-07-28 17:22:21 +02:00
|
|
|
single quote. To include a single quote into such an argument,
|
2006-05-31 13:47:20 +02:00
|
|
|
use two single quotes. 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),
|
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).
|
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 an unquoted argument begins with a colon (<literal>:</literal>),
|
2002-08-10 05:56:24 +02:00
|
|
|
it is taken as a <application>psql</> variable and the value of the
|
2010-01-29 18:44:12 +01:00
|
|
|
variable is used as the argument instead. If the variable name is
|
|
|
|
surrounded by single quotes (e.g. <literal>:'var'</literal>), it
|
|
|
|
will be escaped as an SQL literal and the result will be used as
|
|
|
|
the argument. If the variable name is surrounded by double quotes,
|
|
|
|
it will be escaped as an SQL identifier and the result will be used
|
|
|
|
as the argument.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2002-09-21 20:32:54 +02:00
|
|
|
Arguments that are enclosed in backquotes (<literal>`</literal>)
|
|
|
|
are taken as a command line that is passed to the shell. The
|
|
|
|
output of the command (with any trailing newline removed) is taken
|
|
|
|
as the argument value. The above escape sequences also apply in
|
|
|
|
backquotes.
|
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
|
|
|
|
lowercase, while double quotes (<literal>"</>) protect letters
|
|
|
|
from case conversion and allow incorporation of whitespace into
|
|
|
|
the identifier. Within double quotes, paired double quotes reduce
|
|
|
|
to a single double quote in the resulting name. For example,
|
|
|
|
<literal>FOO"BAR"BAZ</> is interpreted as <literal>fooBARbaz</>,
|
|
|
|
and <literal>"A weird"" name"</> becomes <literal>A weird"
|
|
|
|
name</>.
|
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
|
|
|
|
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>
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>\c</literal> or <literal>\connect</literal> <literal>[ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2006-04-02 22:08:22 +02:00
|
|
|
Establishes a new connection to a <productname>PostgreSQL</>
|
|
|
|
server. If the new connection is successfully made, the
|
|
|
|
previous connection is closed. If any of <replaceable
|
|
|
|
class="parameter">dbname</replaceable>, <replaceable
|
|
|
|
class="parameter">username</replaceable>, <replaceable
|
|
|
|
class="parameter">host</replaceable> or <replaceable
|
|
|
|
class="parameter">port</replaceable> are omitted or specified
|
|
|
|
as <literal>-</literal>, the value of that parameter from the
|
|
|
|
previous connection is used. If there is no previous
|
|
|
|
connection, the <application>libpq</application> default for
|
|
|
|
the parameter's value is used.
|
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>
|
|
|
|
If the connection attempt failed (wrong user name, access
|
2006-04-02 22:08:22 +02:00
|
|
|
denied, etc.), the previous connection will only be kept if
|
|
|
|
<application>psql</application> is in interactive mode. When
|
|
|
|
executing a non-interactive script, processing will
|
|
|
|
immediately stop with an error. This distinction was chosen as
|
|
|
|
a user convenience against typos on the one hand, and a safety
|
|
|
|
mechanism that scripts are not accidentally acting on the
|
|
|
|
wrong database on the other hand.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2011-05-22 14:13:17 +02:00
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
2010-07-20 05:54:19 +02:00
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
2000-02-20 15:29:21 +01:00
|
|
|
<varlistentry>
|
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> ) }
|
2002-07-28 17:22:21 +02:00
|
|
|
{ <literal>from</literal> | <literal>to</literal> }
|
2004-06-18 08:14:31 +02:00
|
|
|
{ <replaceable class="parameter">filename</replaceable> | stdin | stdout | pstdin | pstdout }
|
|
|
|
[ with ]
|
2006-05-26 21:51:29 +02:00
|
|
|
[ binary ]
|
2004-06-18 08:14:31 +02:00
|
|
|
[ oids ]
|
2004-04-22 19:38:16 +02:00
|
|
|
[ delimiter [ as ] '<replaceable class="parameter">character</replaceable>' ]
|
|
|
|
[ null [ as ] '<replaceable class="parameter">string</replaceable>' ]
|
2006-05-26 21:51:29 +02:00
|
|
|
[ csv
|
|
|
|
[ header ]
|
|
|
|
[ quote [ as ] '<replaceable class="parameter">character</replaceable>' ]
|
|
|
|
[ escape [ as ] '<replaceable class="parameter">character</replaceable>' ]
|
2009-07-25 19:04:19 +02:00
|
|
|
[ force quote <replaceable class="parameter">column_list</replaceable> | * ]
|
2006-05-26 21:51:29 +02:00
|
|
|
[ force not null <replaceable class="parameter">column_list</replaceable> ] ]</literal>
|
2002-07-28 17:22:21 +02:00
|
|
|
</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
|
2010-04-03 09:23:02 +02:00
|
|
|
runs an <acronym>SQL</acronym> <xref linkend="SQL-COPY">
|
|
|
|
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>
|
|
|
|
The syntax of the command is similar to that of the
|
2010-04-03 09:23:02 +02:00
|
|
|
<acronym>SQL</acronym> <xref linkend="sql-copy">
|
|
|
|
command. Note that, because of this,
|
2004-06-18 08:14:31 +02:00
|
|
|
special parsing rules apply to the <command>\copy</command>
|
|
|
|
command. In particular, the variable substitution rules and
|
|
|
|
backslash escapes do not apply.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2006-08-31 01:34:22 +02:00
|
|
|
<literal>\copy ... from stdin | to stdout</literal>
|
2004-06-18 08:14:31 +02:00
|
|
|
reads/writes based on the command input and output respectively.
|
|
|
|
All rows are read from the same source that issued the command,
|
|
|
|
continuing until <literal>\.</literal> is read or the stream
|
|
|
|
reaches <acronym>EOF</>. Output is sent to the same place as
|
|
|
|
command output. To read/write from
|
|
|
|
<application>psql</application>'s standard input or output, use
|
|
|
|
<literal>pstdin</> or <literal>pstdout</>. This option is useful
|
|
|
|
for populating tables in-line within a SQL script file.
|
|
|
|
</para>
|
2004-01-21 00:48:56 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
2004-06-18 08:14:31 +02:00
|
|
|
This operation is not as efficient as the <acronym>SQL</acronym>
|
|
|
|
<command>COPY</command> command because all data must pass
|
|
|
|
through the client/server connection. For large
|
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
|
|
|
amounts of data the <acronym>SQL</acronym> command might be preferable.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</tip>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
2011-06-14 22:44:01 +02:00
|
|
|
For each relation (table, view, index, sequence, or foreign table)
|
|
|
|
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.
|
2009-12-25 00:36:39 +01:00
|
|
|
(<quote>Matching the pattern</> is defined in
|
|
|
|
<xref linkend="APP-PSQL-patterns" endterm="APP-PSQL-patterns-title">
|
|
|
|
below.)
|
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>
|
|
|
|
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
|
2011-01-02 05:48:11 +01:00
|
|
|
table, the view definition if the relation is a view, and the generic
|
|
|
|
options if the relation is a foreign table.
|
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
|
2011-01-02 05:48:11 +01:00
|
|
|
equivalent to <command>\dtvsE</command> which will show a list of
|
|
|
|
all visible tables, views, sequences and foreign tables.
|
|
|
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
|
2003-01-07 21:56:07 +01:00
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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.
|
2008-07-03 05:37:17 +02:00
|
|
|
If <literal>+</literal> is appended to the command name, each object
|
2004-07-15 05:56:06 +02:00
|
|
|
is listed with its associated permissions.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2003-01-07 21:56:07 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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.
|
2003-01-07 21:56:07 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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.
|
2003-01-07 21:56:07 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
2002-08-10 05:56:24 +02:00
|
|
|
Shows the descriptions of objects matching the <replaceable
|
|
|
|
class="parameter">pattern</replaceable>, or of all visible objects if
|
2004-06-18 08:14:31 +02:00
|
|
|
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.
|
2009-04-04 02:39:14 +02:00
|
|
|
<quote>Object</quote> covers aggregates, functions, operators,
|
|
|
|
types, relations (tables, views, indexes, sequences), large
|
|
|
|
objects, rules, and triggers. For example:
|
2002-07-28 17:22:21 +02:00
|
|
|
<programlisting>
|
2005-01-22 23:31:52 +01:00
|
|
|
=> <userinput>\dd version</userinput>
|
2002-08-10 05:56:24 +02:00
|
|
|
Object descriptions
|
|
|
|
Schema | Name | Object | Description
|
|
|
|
------------+---------+----------+---------------------------
|
|
|
|
pg_catalog | version | function | PostgreSQL version string
|
2002-07-28 17:22:21 +02:00
|
|
|
(1 row)
|
|
|
|
</programlisting>
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
|
|
|
<para>
|
2004-04-22 19:38:16 +02:00
|
|
|
Descriptions for objects can be created with the <xref
|
2010-04-03 09:23:02 +02:00
|
|
|
linkend="sql-comment">
|
2004-04-22 19:38:16 +02:00
|
|
|
<acronym>SQL</acronym> command.
|
|
|
|
</para>
|
1999-11-04 23:07:57 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2009-10-05 21:24:49 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
2010-04-03 09:23:02 +02:00
|
|
|
The <xref linkend="sql-alterdefaultprivileges"> command is used to set
|
2009-10-05 21:24:49 +02:00
|
|
|
default access privileges. The meaning of the
|
|
|
|
privilege display is explained under
|
2010-04-03 09:23:02 +02:00
|
|
|
<xref linkend="sql-grant">.
|
2009-10-05 21:24:49 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists domains. If <replaceable
|
2002-08-10 05:56:24 +02:00
|
|
|
class="parameter">pattern</replaceable>
|
2009-12-25 00:36:39 +01:00
|
|
|
is specified, only domains 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>
|
|
|
|
|
|
|
|
|
2011-01-02 05:48:11 +01:00
|
|
|
<varlistentry>
|
2011-05-22 14:13:17 +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>\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-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>,
|
|
|
|
<literal>i</literal>, <literal>s</literal>,
|
|
|
|
<literal>t</literal>, and <literal>v</literal>
|
|
|
|
stand for foreign table, index, sequence, table, and view,
|
|
|
|
respectively.
|
|
|
|
You can specify any or all of
|
|
|
|
these letters, in any order, to obtain a listing of objects
|
|
|
|
of these types. For example, <literal>\dit</> lists indexes
|
|
|
|
and tables. If <literal>+</literal> is
|
|
|
|
appended to the command name, each object is listed with its
|
|
|
|
physical size on disk and its 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>
|
|
|
|
|
|
|
|
|
2008-12-19 17:25:19 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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
|
2008-12-19 17:25:19 +01:00
|
|
|
server's ACL, type, version, and options.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2011-05-22 14:13:17 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\det[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<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>
|
|
|
|
is used, generic options are also displayed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2008-12-19 17:25:19 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
is used, the ACL and options of the foreign-data wrapper are
|
|
|
|
also shown.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\df[antwS+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists functions, together with their arguments, return types, and
|
|
|
|
function types, which are classified as <quote>agg</> (aggregate),
|
|
|
|
<quote>normal</>, <quote>trigger</>, or <quote>window</>.
|
|
|
|
To display only functions
|
|
|
|
of specific type(s), add the corresponding letters <literal>a</>,
|
|
|
|
<literal>n</>, <literal>t</>, or <literal>w</> to the command.
|
|
|
|
If <replaceable
|
2009-04-21 17:49:06 +02:00
|
|
|
class="parameter">pattern</replaceable> is specified, only
|
|
|
|
functions whose names match the pattern are shown. If the
|
|
|
|
form <literal>\df+</literal> is used, additional information
|
|
|
|
about each function, including volatility, language, source
|
|
|
|
code and description, is shown. 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.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
2002-08-23 03:27:44 +02:00
|
|
|
|
2009-12-25 00:36:39 +01:00
|
|
|
<tip>
|
2004-03-30 17:54:33 +02:00
|
|
|
<para>
|
2009-04-09 00:29:30 +02:00
|
|
|
To look up functions taking arguments or returning values of a specific
|
2009-12-25 00:36:39 +01:00
|
|
|
type, use your pager's search capability to scroll through the
|
|
|
|
<literal>\df</> output.
|
2004-03-30 17:54:33 +02:00
|
|
|
</para>
|
2009-12-25 00:36:39 +01:00
|
|
|
</tip>
|
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>
|
|
|
|
|
2007-08-22 06:45:20 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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>
|
|
|
|
|
|
|
|
|
2003-12-01 23:21:54 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\dg[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
2003-12-01 23:21:54 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-12-25 00:36:39 +01:00
|
|
|
Lists database roles. If <replaceable
|
2004-04-22 19:38:16 +02:00
|
|
|
class="parameter">pattern</replaceable> is specified, only
|
2005-08-14 20:49:30 +02:00
|
|
|
those roles whose names match the pattern are listed.
|
2009-07-24 21:35:44 +02:00
|
|
|
(This command is now effectively the same as <literal>\du</literal>).
|
2009-10-05 21:24:49 +02:00
|
|
|
If the form <literal>\dg+</literal> is used, additional information
|
|
|
|
is shown about each role, including the comment for each role.
|
2003-12-01 23:21:54 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2002-07-28 17:22:21 +02: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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-20 06:00:30 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\dL[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<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
|
|
|
|
2003-01-07 21:56:07 +01:00
|
|
|
<varlistentry>
|
2010-11-07 02:41:14 +01: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>
|
|
|
|
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\do[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 operators with their operand and return 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.
|
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.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
|
2011-02-12 14:54:13 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\dO[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\dp [ <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
|
|
|
|
pattern are listed.
|
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>
|
2010-04-03 09:23:02 +02:00
|
|
|
The <xref linkend="sql-grant"> and
|
|
|
|
<xref linkend="sql-revoke">
|
2009-10-05 21:24:49 +02:00
|
|
|
commands are used to set access privileges. The meaning of the
|
|
|
|
privilege display is explained under
|
2010-04-03 09:23:02 +02:00
|
|
|
<xref linkend="sql-grant">.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2009-10-08 18:34:01 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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
|
|
|
|
<literal>*</> is specified, all settings are listed, including those
|
|
|
|
not role-specific or database-specific, respectively.
|
2009-10-08 18:34:01 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-04-03 09:23:02 +02:00
|
|
|
The <xref linkend="sql-alterrole"> and
|
|
|
|
<xref linkend="sql-alterdatabase">
|
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
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01: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
|
|
|
|
listed with its internal name and size, as well as its allowed values
|
|
|
|
if it is an <type>enum</> type.
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\du[+] [ <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 database roles. If <replaceable
|
2009-04-04 02:39:14 +02:00
|
|
|
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
|
|
|
|
is shown about each role, including the comment for each role.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-02-08 22:08:41 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\dx[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
|
|
|
<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
|
|
|
|
|
|
|
<varlistentry>
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>\e</literal> or <literal>\edit</> <literal> <optional> <replaceable class="parameter">filename</> </optional> <optional> <replaceable class="parameter">line_number</> </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
|
|
|
|
specified, the file is edited; after the editor exits, its
|
2010-08-12 02:40:59 +02:00
|
|
|
content is copied back to the query buffer. If no <replaceable
|
|
|
|
class="parameter">filename</replaceable> is given, the current query
|
|
|
|
buffer is copied to a temporary file which is then edited in the same
|
|
|
|
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>
|
|
|
|
The new query buffer is then re-parsed according to the normal
|
|
|
|
rules of <application>psql</application>, where the whole buffer
|
|
|
|
is treated as a single line. (Thus you cannot make scripts this
|
2010-08-12 02:40:59 +02:00
|
|
|
way. Use <command>\i</command> for that.) This means that
|
|
|
|
if the query ends with (or contains) a semicolon, it is
|
|
|
|
immediately executed. Otherwise it will merely wait in the
|
|
|
|
query buffer; type semicolon or <literal>\g</> to send it, or
|
|
|
|
<literal>\r</> to cancel.
|
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
|
|
|
<tip>
|
|
|
|
<para>
|
2010-08-12 02:40:59 +02:00
|
|
|
<application>psql</application> checks the environment
|
2002-07-28 17:22:21 +02:00
|
|
|
variables <envar>PSQL_EDITOR</envar>, <envar>EDITOR</envar>, and
|
|
|
|
<envar>VISUAL</envar> (in that order) for an editor to use. If
|
2005-01-04 04:58:16 +01:00
|
|
|
all of them are unset, <filename>vi</filename> is used on Unix
|
|
|
|
systems, <filename>notepad.exe</filename> on Windows systems.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</tip>
|
2010-08-12 02:40:59 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
If a line number is specified, <application>psql</application> will
|
|
|
|
position the cursor on the specified line of the file or query buffer.
|
|
|
|
This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
|
|
|
|
variable to be set, so that <application>psql</application> knows how
|
|
|
|
to specify the line number to the editor. Note that if a single
|
|
|
|
all-digits argument is given, <application>psql</application> assumes
|
|
|
|
it is a line number not a file name.
|
|
|
|
</para>
|
2002-07-28 17:22:21 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-05-22 14:13:17 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\echo <replaceable class="parameter">text</replaceable> [ ... ]</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Prints the arguments to the standard output, separated by one
|
|
|
|
space and followed by a newline. This can be useful to
|
|
|
|
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
|
|
|
|
newline is not written.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
If you use the <command>\o</command> command to redirect your
|
|
|
|
query output you might wish to use <command>\qecho</command>
|
|
|
|
instead of this command.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
2008-09-06 02:01:25 +02:00
|
|
|
<varlistentry>
|
2010-08-12 02:40:59 +02:00
|
|
|
<term><literal>\ef <optional> <replaceable class="parameter">function_description</> <optional> <replaceable class="parameter">line_number</> </optional> </optional> </literal></term>
|
2008-09-06 02:01:25 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This command fetches and edits the definition of the named function,
|
|
|
|
in the form of a <command>CREATE OR REPLACE FUNCTION</> command.
|
2010-08-12 02:40:59 +02:00
|
|
|
Editing is done in the same way as for <literal>\edit</>.
|
2008-09-06 02:01:25 +02:00
|
|
|
After the editor exits, the updated command waits in the query buffer;
|
|
|
|
type semicolon or <literal>\g</> to send it, or <literal>\r</>
|
|
|
|
to cancel.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The target function can be specified by name alone, or by name
|
|
|
|
and arguments, for example <literal>foo(integer, text)</>.
|
|
|
|
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>
|
|
|
|
If no function is specified, a blank <command>CREATE FUNCTION</>
|
|
|
|
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
|
|
|
|
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).
|
|
|
|
This feature requires the <varname>EDITOR_LINENUMBER_SWITCH</varname>
|
|
|
|
variable to be set, so that <application>psql</application> knows how
|
|
|
|
to specify the line number to the editor.
|
|
|
|
</para>
|
2008-09-06 02:01:25 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\encoding [ <replaceable class="parameter">encoding</replaceable> ]</literal></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Sets the client character set encoding. Without an argument, this command
|
2003-02-13 06:37:44 +01:00
|
|
|
shows the current encoding.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
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
|
2003-03-24 15:32:51 +01:00
|
|
|
is the vertical bar (<literal>|</literal>). See also
|
2002-07-28 17:22:21 +02:00
|
|
|
<command>\pset</command> for a generic way of setting output
|
|
|
|
options.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\g</literal> [ { <replaceable class="parameter">filename</replaceable> | <literal>|</literal><replaceable class="parameter">command</replaceable> } ]</term>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Sends the current query input buffer to the server and
|
2005-01-04 04:58:16 +01:00
|
|
|
optionally stores the query's output in <replaceable
|
2002-07-28 17:22:21 +02:00
|
|
|
class="parameter">filename</replaceable> or pipes the output
|
2005-01-04 04:58:16 +01:00
|
|
|
into a separate Unix shell executing <replaceable
|
2002-07-28 17:22:21 +02:00
|
|
|
class="parameter">command</replaceable>. A bare
|
|
|
|
<literal>\g</literal> is virtually equivalent to a semicolon. A
|
|
|
|
<literal>\g</literal> with argument is a <quote>one-shot</quote>
|
|
|
|
alternative to the <command>\o</command> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
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
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\H</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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\i <replaceable class="parameter">filename</replaceable></literal></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>
|
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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\l</literal> (or <literal>\list</literal>)</term>
|
2004-04-22 19:38:16 +02:00
|
|
|
<term><literal>\l+</literal> (or <literal>\list+</literal>)</term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-03-30 20:10:20 +02:00
|
|
|
List the names, owners, character set encodings, and access privileges
|
|
|
|
of all the databases in the server.
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\o</literal> [ {<replaceable class="parameter">filename</replaceable> | <literal>|</literal><replaceable class="parameter">command</replaceable>} ]</term>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-07-28 17:22:21 +02:00
|
|
|
Saves future query results to the file <replaceable
|
|
|
|
class="parameter">filename</replaceable> or pipes future results
|
|
|
|
into a separate Unix shell to execute <replaceable
|
|
|
|
class="parameter">command</replaceable>. If no arguments are
|
2003-03-24 15:32:51 +01:00
|
|
|
specified, the query output will be reset to the standard output.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<para>
|
|
|
|
<quote>Query results</quote> includes all tables, command
|
|
|
|
responses, and notices obtained from the database server, as
|
|
|
|
well as output of various backslash commands that query the
|
|
|
|
database (such as <command>\d</command>), but not error
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2002-07-28 17:22:21 +02:00
|
|
|
<term><literal>\p</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.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2005-12-18 03:17:16 +01:00
|
|
|
<varlistentry>
|
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
|
|
|
|
sends it to the server as an <command>ALTER ROLE</> command. This
|
|
|
|
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>
|
|
|
|
|
2007-02-23 19:20:59 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\prompt [ <replaceable class="parameter">text</replaceable> ] <replaceable class="parameter">name</replaceable></literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Prompts the user to set variable <replaceable
|
|
|
|
class="parameter">name</>. An optional prompt, <replaceable
|
2010-08-17 06:37:21 +02:00
|
|
|
class="parameter">text</>, can be specified. (For multiword
|
|
|
|
prompts, use single quotes.)
|
2007-02-23 19:20:59 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
By default, <literal>\prompt</> uses the terminal for input and
|
|
|
|
output. However, if the <option>-f</> command line switch is
|
|
|
|
used, <literal>\prompt</> uses standard input and standard output.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
2009-11-22 23:06:30 +01: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>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Adjustable printing options are:
|
|
|
|
<variablelist>
|
2011-05-22 14:13:17 +02:00
|
|
|
<varlistentry>
|
|
|
|
<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,
|
|
|
|
but this depends on the particular format. In
|
|
|
|
<acronym>HTML</acronym> format, this will translate directly
|
|
|
|
into the <literal>border=...</literal> attribute; in the
|
|
|
|
other formats only values 0 (no border), 1 (internal dividing lines),
|
|
|
|
and 2 (table frame) make sense.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>columns</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the target width for the <literal>wrapped</> format, and also
|
|
|
|
the width limit for determining whether output is wide enough to
|
|
|
|
require the pager.
|
|
|
|
Zero (the default) causes the target width to be controlled by the
|
|
|
|
environment variable <envar>COLUMNS</>, or the detected screen width
|
|
|
|
if <envar>COLUMNS</> is not set.
|
|
|
|
In addition, if <literal>columns</> is zero then the
|
|
|
|
<literal>wrapped</> format only affects screen output.
|
|
|
|
If <literal>columns</> is nonzero then file and pipe output is
|
|
|
|
wrapped to that width as well.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>expanded</literal> (or <literal>x</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 expanded mode. If <replaceable
|
|
|
|
class="parameter">value</replaceable> is omitted the command toggles
|
|
|
|
between regular and expanded mode.
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>fieldsep</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies the field separator to be used in unaligned output
|
|
|
|
format. That way one can create, for example, tab- or
|
|
|
|
comma-separated output, which other programs might prefer. To
|
|
|
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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
|
|
|
|
(the <literal>(<replaceable>n</> rows)</literal> count).
|
|
|
|
If <replaceable class="parameter">value</replaceable> is omitted the
|
|
|
|
command toggles footer display on or off.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>format</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the output format to one of <literal>unaligned</literal>,
|
2008-07-03 05:37:17 +02:00
|
|
|
<literal>aligned</literal>, <literal>wrapped</literal>,
|
2008-05-08 19:04:26 +02:00
|
|
|
<literal>html</literal>,
|
2005-06-09 17:27:27 +02:00
|
|
|
<literal>latex</literal>, or <literal>troff-ms</literal>.
|
|
|
|
Unique abbreviations are allowed. (That would mean one letter
|
2005-06-13 08:36:22 +02:00
|
|
|
is enough.)
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
<literal>unaligned</> 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
|
|
|
|
in by other programs (for example, tab-separated or comma-separated
|
|
|
|
format).
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<literal>aligned</literal> format is the standard, human-readable,
|
2010-02-19 04:50:03 +01:00
|
|
|
nicely formatted text output; this is the default.
|
2008-05-08 19:04:26 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
<literal>wrapped</> format is like <literal>aligned</> but wraps
|
|
|
|
wide data values across lines to make the output fit in the target
|
|
|
|
column width. The target width is determined as described under
|
|
|
|
the <literal>columns</> option. Note that <application>psql</> will
|
|
|
|
not attempt to wrap column header titles; therefore,
|
|
|
|
<literal>wrapped</> format behaves the same as <literal>aligned</>
|
|
|
|
if the total width needed for column headers exceeds the target.
|
2008-05-08 19:04:26 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
The <literal>html</>, <literal>latex</>, and <literal>troff-ms</>
|
|
|
|
formats put out tables that are intended to
|
2004-06-18 08:14:31 +02:00
|
|
|
be included in documents using the respective mark-up
|
|
|
|
language. They are not complete documents! (This might not be
|
|
|
|
so dramatic in <acronym>HTML</acronym>, but in LaTeX you must
|
|
|
|
have a complete document wrapper.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2009-10-13 23:04:01 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>linestyle</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the border line drawing style to one
|
2009-11-22 06:20:41 +01:00
|
|
|
of <literal>ascii</literal>, <literal>old-ascii</literal>
|
|
|
|
or <literal>unicode</literal>.
|
2009-10-13 23:04:01 +02:00
|
|
|
Unique abbreviations are allowed. (That would mean one
|
|
|
|
letter is enough.)
|
2009-11-25 21:26:31 +01:00
|
|
|
The default setting is <literal>ascii</>.
|
2009-11-22 23:06:30 +01:00
|
|
|
This option only affects the <literal>aligned</> and
|
|
|
|
<literal>wrapped</> output formats.
|
2009-10-13 23:04:01 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-11-22 06:20:41 +01:00
|
|
|
<literal>ascii</literal> style uses plain <acronym>ASCII</acronym>
|
|
|
|
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
|
|
|
|
(<literal>.</>) 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>
|
2009-11-22 06:20:41 +01:00
|
|
|
<literal>old-ascii</literal> style uses plain <acronym>ASCII</>
|
|
|
|
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
|
2009-11-22 06:20:41 +01:00
|
|
|
to the next without a newline character, a <literal>;</>
|
|
|
|
symbol is used in place of the left-hand column separator.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<literal>unicode</literal> style uses Unicode box-drawing characters.
|
|
|
|
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>
|
2009-11-22 23:06:30 +01:00
|
|
|
When the <literal>border</> setting is greater than zero,
|
|
|
|
this 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
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
2005-07-10 05:46:13 +02:00
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
2004-06-18 08:14:31 +02:00
|
|
|
<varlistentry>
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>pager</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-05-22 14:13:17 +02:00
|
|
|
Controls use of a pager program for query and <application>psql</>
|
|
|
|
help output. If the environment variable <envar>PAGER</envar>
|
|
|
|
is set, the output is piped to the specified program.
|
|
|
|
Otherwise a platform-dependent default (such as
|
|
|
|
<filename>more</filename>) is used.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2011-05-22 14:13:17 +02:00
|
|
|
When the <literal>pager</> option is <literal>off</>, the pager
|
|
|
|
program is not used. When the <literal>pager</> option is
|
|
|
|
<literal>on</>, 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</> option can also be set to <literal>always</>,
|
|
|
|
which causes the pager to be used for all terminal output regardless
|
|
|
|
of whether it fits on the screen. <literal>\pset pager</>
|
|
|
|
without a <replaceable class="parameter">value</replaceable>
|
|
|
|
toggles pager use on and off.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
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>
|
2009-11-22 23:06:30 +01:00
|
|
|
Specifies attributes to be placed inside the
|
|
|
|
<acronym>HTML</acronym> <sgmltag>table</sgmltag> tag in
|
|
|
|
<literal>html</> output format. 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>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2011-05-22 14:13:17 +02:00
|
|
|
<term><literal>title</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
|
|
|
|
2011-05-22 14:13:17 +02:00
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
Illustrations of how these different formats look can be seen in
|
2004-06-18 08:14:31 +02:00
|
|
|
the <xref linkend="APP-PSQL-examples"
|
|
|
|
endterm="APP-PSQL-examples-title"> section.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
There are various shortcut commands for <command>\pset</command>. See
|
|
|
|
<command>\a</command>, <command>\C</command>, <command>\H</command>,
|
|
|
|
<command>\t</command>, <command>\T</command>, and <command>\x</command>.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
2009-11-22 23:06:30 +01:00
|
|
|
It is an error to call <command>\pset</command> without any
|
|
|
|
arguments. In the future this case might show the current status
|
2004-06-18 08:14:31 +02:00
|
|
|
of all printing options.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
</listitem>
|
2002-07-28 17:22:21 +02:00
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\q</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Quits the <application>psql</application> program.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
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
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\r</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Resets (clears) the query buffer.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
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>
|
|
|
|
Print or save the 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. This option is only available
|
|
|
|
if <application>psql</application> is configured to use the
|
2004-12-13 19:05:10 +01:00
|
|
|
<acronym>GNU</acronym> <application>Readline</application> library.
|
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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
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>
|
|
|
|
Sets the internal variable <replaceable
|
|
|
|
class="parameter">name</replaceable> to <replaceable
|
|
|
|
class="parameter">value</replaceable> or, if more than one value
|
|
|
|
is given, to the concatenation of all of them. If no second
|
|
|
|
argument is given, the variable is just set with no value. To
|
|
|
|
unset a variable, use the <command>\unset</command> command.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Valid variable names can contain characters, digits, and
|
|
|
|
underscores. See the section <xref
|
|
|
|
linkend="APP-PSQL-variables"
|
|
|
|
endterm="APP-PSQL-variables-title"> below for details.
|
|
|
|
Variable names are case-sensitive.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Although you are welcome to set any variable to anything you
|
|
|
|
want, <application>psql</application> treats several variables
|
|
|
|
as special. They are documented in the section about variables.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
This command is totally separate from the <acronym>SQL</acronym>
|
2010-04-03 09:23:02 +02:00
|
|
|
command <xref linkend="SQL-SET">.
|
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
|
|
|
|
2010-08-14 15:59:49 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\sf[+] <replaceable class="parameter">function_description</> </literal></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This command fetches and shows the definition of the named function,
|
|
|
|
in the form of a <command>CREATE OR REPLACE FUNCTION</> command.
|
|
|
|
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
|
|
|
|
and arguments, for example <literal>foo(integer, text)</>.
|
|
|
|
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>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
|
|
|
<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
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
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
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
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>
|
2008-06-11 12:48:17 +02:00
|
|
|
Without parameter, toggles a display of how long each SQL statement
|
|
|
|
takes, in milliseconds. With parameter, sets same.
|
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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\w</literal> <replaceable class="parameter">filename</replaceable></term>
|
|
|
|
<term><literal>\w</literal> <literal>|</><replaceable class="parameter">command</replaceable></term>
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Outputs the current query buffer to the file <replaceable
|
|
|
|
class="parameter">filename</replaceable> or pipes it to the Unix
|
|
|
|
command <replaceable class="parameter">command</replaceable>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\x</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-06-13 08:36:22 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
2009-12-25 00:36:39 +01:00
|
|
|
<term><literal>\z [ <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
|
|
|
|
pattern are listed.
|
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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
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>
|
|
|
|
Escapes to a separate Unix shell or executes the Unix command
|
|
|
|
<replaceable class="parameter">command</replaceable>. The
|
2010-02-19 04:50:03 +01:00
|
|
|
arguments are not further interpreted; the shell will see them
|
2009-12-25 00:36:39 +01:00
|
|
|
as-is.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>\?</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-03-24 15:32:51 +01:00
|
|
|
Shows help information about the backslash commands.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
1999-05-20 07:40:27 +02:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
2002-08-10 05:56:24 +02:00
|
|
|
|
2006-10-10 01:31:29 +02:00
|
|
|
<refsect3 id="APP-PSQL-patterns">
|
|
|
|
<title id="APP-PSQL-patterns-title">Patterns</title>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>patterns</primary>
|
|
|
|
<secondary>in psql and pg_dump</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2002-08-10 05:56:24 +02:00
|
|
|
<para>
|
|
|
|
The various <literal>\d</> commands accept a <replaceable
|
|
|
|
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;
|
|
|
|
for example, <literal>\dt FOO</> will display the table named
|
|
|
|
<literal>foo</>. As in SQL names, placing double quotes around
|
|
|
|
a pattern stops folding to lower case. Should you need to include
|
|
|
|
an actual double quote character in a pattern, write it as a pair
|
|
|
|
of double quotes within a double-quote sequence; again this is in
|
|
|
|
accord with the rules for SQL quoted identifiers. For example,
|
|
|
|
<literal>\dt "FOO""BAR"</> will display the table named
|
|
|
|
<literal>FOO"BAR</> (not <literal>foo"bar</>). Unlike the normal
|
|
|
|
rules for SQL names, you can put double quotes around just part
|
|
|
|
of a pattern, for instance <literal>\dt FOO"FOO"BAR</> will display
|
|
|
|
the table named <literal>fooFOObar</>.
|
|
|
|
</para>
|
|
|
|
|
2009-12-25 00:36:39 +01:00
|
|
|
<para>
|
|
|
|
Whenever the <replaceable class="parameter">pattern</replaceable> parameter
|
|
|
|
is omitted completely, the <literal>\d</> commands display all objects
|
|
|
|
that are visible in the current schema search path — this is
|
|
|
|
equivalent to using <literal>*</> as the pattern.
|
|
|
|
(An object is said to be <firstterm>visible</> if its
|
|
|
|
containing schema is in the search path and no object of the same
|
|
|
|
kind and name appears earlier in the search path. This is equivalent to the
|
|
|
|
statement that the object can be referenced by name without explicit
|
|
|
|
schema qualification.)
|
|
|
|
To see all objects in the database regardless of visibility,
|
|
|
|
use <literal>*.*</> as the pattern.
|
|
|
|
</para>
|
|
|
|
|
2006-10-10 01:31:29 +02:00
|
|
|
<para>
|
|
|
|
Within a pattern, <literal>*</> matches any sequence of characters
|
|
|
|
(including no characters) and <literal>?</> matches any single character.
|
|
|
|
(This notation is comparable to Unix shell file name patterns.)
|
2009-12-25 00:36:39 +01:00
|
|
|
For example, <literal>\dt int*</> displays tables whose names
|
2006-10-10 01:31:29 +02:00
|
|
|
begin with <literal>int</>. But within double quotes, <literal>*</>
|
|
|
|
and <literal>?</> lose these special meanings and are just matched
|
|
|
|
literally.
|
2002-08-10 05:56:24 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2006-10-10 01:31:29 +02:00
|
|
|
A pattern that contains a dot (<literal>.</>) is interpreted as a schema
|
2002-08-10 05:56:24 +02:00
|
|
|
name pattern followed by an object name pattern. For example,
|
2007-07-10 02:21:31 +02:00
|
|
|
<literal>\dt foo*.*bar*</> displays all tables whose table name
|
|
|
|
includes <literal>bar</> that are in schemas whose schema name
|
2006-10-10 01:31:29 +02:00
|
|
|
starts with <literal>foo</>. 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
|
|
|
|
literally.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Advanced users can use regular-expression notations such as character
|
|
|
|
classes, for example <literal>[0-9]</> to match any digit. All regular
|
|
|
|
expression special characters work as specified in
|
|
|
|
<xref linkend="functions-posix-regexp">, except for <literal>.</> which
|
|
|
|
is taken as a separator as mentioned above, <literal>*</> which is
|
2007-07-10 02:21:31 +02:00
|
|
|
translated to the regular-expression notation <literal>.*</>,
|
|
|
|
<literal>?</> which is translated to <literal>.</>, and
|
|
|
|
<literal>$</> which is matched literally. You can emulate
|
2006-10-10 01:31:29 +02:00
|
|
|
these pattern characters at need by writing
|
|
|
|
<literal>?</> for <literal>.</>,
|
|
|
|
<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>.
|
2007-07-10 02:21:31 +02:00
|
|
|
<literal>$</> is not needed as a regular-expression character since
|
|
|
|
the pattern must match the whole name, unlike the usual
|
|
|
|
interpretation of regular expressions (in other words, <literal>$</>
|
|
|
|
is automatically appended to your pattern). Write <literal>*</> at the
|
|
|
|
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
|
|
|
|
patterns (i.e., the argument of <literal>\do</>).
|
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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect3 id="APP-PSQL-variables">
|
1999-11-04 23:07:57 +01:00
|
|
|
<title id="APP-PSQL-variables-title">Variables</title>
|
|
|
|
|
|
|
|
<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
|
2002-06-20 18:00:44 +02:00
|
|
|
can be any string of any length. To set variables, use the
|
|
|
|
<application>psql</application> meta-command
|
|
|
|
<command>\set</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
|
|
|
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
|
2002-06-20 18:00:44 +02:00
|
|
|
the name with a colon and use it as the argument of any slash
|
|
|
|
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
|
|
|
testdb=> <userinput>\echo :foo</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
bar
|
* 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
|
|
|
</para>
|
|
|
|
|
|
|
|
<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>
|
2002-06-20 18:00:44 +02:00
|
|
|
If you call <command>\set</command> without a second argument, the
|
2003-06-28 02:12:40 +02:00
|
|
|
variable is set, with an empty string as value. To unset (or delete) a
|
2002-06-20 18:00:44 +02:00
|
|
|
variable, use the command <command>\unset</command>.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
<application>psql</application>'s internal variable names can
|
|
|
|
consist of letters, numbers, and underscores in any order and any
|
2003-06-28 02:12:40 +02:00
|
|
|
number of them. A number of these variables are treated specially
|
2002-06-20 18:00:44 +02:00
|
|
|
by <application>psql</application>. They indicate certain option
|
|
|
|
settings that can be changed at run time by altering the value of
|
2010-02-19 04:50:03 +01:00
|
|
|
the variable or that represent some state of the application. Although
|
2002-06-20 18:00:44 +02:00
|
|
|
you can use these variables for any other purpose, this is not
|
|
|
|
recommended, as the program behavior might grow really strange
|
|
|
|
really quickly. By convention, all specially treated variables
|
|
|
|
consist of all upper-case letters (and possibly numbers and
|
|
|
|
underscores). To ensure maximum compatibility in the future, avoid
|
2003-06-28 02:12:40 +02:00
|
|
|
using such variable names for your own purposes. A list of all specially
|
|
|
|
treated variables follows.
|
2003-03-24 15:32:51 +01:00
|
|
|
</para>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<variablelist>
|
2003-06-28 02:12:40 +02:00
|
|
|
<varlistentry>
|
2004-04-22 19:38:16 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>autocommit</primary>
|
|
|
|
<secondary>psql</secondary>
|
|
|
|
</indexterm>
|
2003-06-28 02:12:40 +02:00
|
|
|
<term><varname>AUTOCOMMIT</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When <literal>on</> (the default), each SQL command is automatically
|
|
|
|
committed upon successful completion. To postpone commit in this
|
|
|
|
mode, you must enter a <command>BEGIN</> or <command>START
|
|
|
|
TRANSACTION</> SQL command. When <literal>off</> or unset, SQL
|
|
|
|
commands are not committed until you explicitly issue
|
|
|
|
<command>COMMIT</> or <command>END</>. The autocommit-off
|
|
|
|
mode works by issuing an implicit <command>BEGIN</> for you, just
|
|
|
|
before any command that is not already in a transaction block and
|
|
|
|
is not itself a <command>BEGIN</> or other transaction-control
|
2004-09-20 20:51:19 +02:00
|
|
|
command, nor a command that cannot be executed inside a transaction
|
|
|
|
block (such as <command>VACUUM</>).
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
In autocommit-off mode, you must explicitly abandon any failed
|
|
|
|
transaction by entering <command>ABORT</> or <command>ROLLBACK</>.
|
|
|
|
Also keep in mind that if you exit the session
|
|
|
|
without committing, your work will be lost.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
The autocommit-on mode is <productname>PostgreSQL</>'s traditional
|
|
|
|
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>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
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
|
|
|
|
start-up), but can be unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>ECHO</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If set to <literal>all</literal>, all lines
|
2005-01-04 04:58:16 +01:00
|
|
|
entered from the keyboard or from a script are written to the standard output
|
2004-06-18 08:14:31 +02:00
|
|
|
before they are parsed or executed. To select this behavior on program
|
|
|
|
start-up, use the switch <option>-a</option>. If set to
|
|
|
|
<literal>queries</literal>,
|
|
|
|
<application>psql</application> merely prints all queries as
|
|
|
|
they are sent to the server. The switch for this is
|
|
|
|
<option>-e</option>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>ECHO_HIDDEN</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When this variable is set and a backslash command queries the
|
|
|
|
database, the query is first shown. This way you can study the
|
|
|
|
<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
|
|
|
|
the variable to the value <literal>noexec</literal>, the queries are
|
|
|
|
just shown but are not actually sent to the server and executed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2010-08-12 02:40:59 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><varname>EDITOR_LINENUMBER_SWITCH</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When <command>\edit</command> or <command>\ef</command> is used with a
|
|
|
|
line number argument, this variable specifies the command-line switch
|
|
|
|
used to pass the line number to the user's editor. For editors such
|
|
|
|
as <productname>emacs</> or <productname>vi</>, you can simply set
|
|
|
|
this variable to a plus sign. Include a trailing space in the value
|
|
|
|
of the variable if there needs to be space between the switch name and
|
|
|
|
the line number.
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
\set EDITOR_LINENUMBER_SWITCH +
|
|
|
|
\set EDITOR_LINENUMBER_SWITCH '--line '
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2000-02-20 15:29:21 +01:00
|
|
|
<varlistentry>
|
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.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-02-20 15:29:21 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2006-08-30 00:25:08 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><varname>FETCH_COUNT</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If this variable is set to an integer value > 0,
|
|
|
|
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>
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
Although you can use any output format with this feature,
|
|
|
|
the default <literal>aligned</> format tends to look bad
|
|
|
|
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>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
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
|
|
|
|
unset, or if set to any other value than those above, all lines
|
|
|
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><varname>HISTFILE</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-11-05 00:14:02 +01:00
|
|
|
The file name that will be used to store the history list. The default
|
2007-02-01 01:28:19 +01:00
|
|
|
value is <filename>~/.psql_history</filename>. For example, putting:
|
2005-06-10 17:34:26 +02:00
|
|
|
<programlisting>
|
2005-06-10 18:31:48 +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>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>HISTSIZE</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
The number of commands to store in the command history. The
|
|
|
|
default value is 500.
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
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
|
|
|
|
start-up), but can be unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>IGNOREEOF</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-09-21 20:32:54 +02:00
|
|
|
If unset, sending an <acronym>EOF</> character (usually
|
|
|
|
<keycombo action="simul"><keycap>Control</><keycap>D</></>)
|
|
|
|
to an interactive session of <application>psql</application>
|
|
|
|
will terminate the application. If set to a numeric value,
|
|
|
|
that many <acronym>EOF</> characters are ignored before the
|
|
|
|
application terminates. If the variable is set but has no
|
|
|
|
numeric value, the default is 10.
|
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>
|
|
|
|
|
|
|
|
<varlistentry>
|
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.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2005-04-28 15:09:59 +02:00
|
|
|
<varlistentry>
|
|
|
|
<indexterm>
|
|
|
|
<primary>rollback</primary>
|
|
|
|
<secondary>psql</secondary>
|
|
|
|
</indexterm>
|
|
|
|
<term><varname>ON_ERROR_ROLLBACK</varname></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When <literal>on</>, if a statement in a transaction block
|
|
|
|
generates an error, the error is ignored and the transaction
|
|
|
|
continues. When <literal>interactive</>, such errors are only
|
|
|
|
ignored in interactive sessions, and not when reading script
|
|
|
|
files. When <literal>off</> (the default), a statement in a
|
|
|
|
transaction block that generates an error aborts the entire
|
|
|
|
transaction. The on_error_rollback-on mode works by issuing an
|
2005-10-30 04:01:49 +01:00
|
|
|
implicit <command>SAVEPOINT</> for you, just before each command
|
2005-04-28 15:09:59 +02:00
|
|
|
that is in a transaction block, and rolls back to the savepoint
|
|
|
|
on error.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2000-02-10 21:08:58 +01:00
|
|
|
<varlistentry>
|
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
|
2011-06-17 06:54:08 +02:00
|
|
|
variable is set, it will instead stop 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,
|
|
|
|
any currently running scripts (the toplevel script, if any, and any
|
|
|
|
other scripts which it may have in invoked) will be terminated
|
|
|
|
immediately. If the toplevel command string contained multiple SQL
|
|
|
|
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>
|
|
|
|
|
1999-11-04 23:07:57 +01:00
|
|
|
<varlistentry>
|
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
|
|
|
|
program start-up), but can be unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
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
|
|
|
|
linkend="APP-PSQL-prompting"
|
|
|
|
endterm="APP-PSQL-prompting-title"> below.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>QUIET</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This variable is equivalent to the command line option
|
|
|
|
<option>-q</option>. It is probably not too useful in
|
|
|
|
interactive mode.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>SINGLELINE</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This variable is equivalent to the command line option
|
|
|
|
<option>-S</option>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2002-09-21 20:32:54 +02:00
|
|
|
<term><varname>SINGLESTEP</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This variable is equivalent to the command line option
|
|
|
|
<option>-s</option>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
|
|
|
<varlistentry>
|
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
|
|
|
|
start-up), but can be unset.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
2003-06-28 02:12:40 +02:00
|
|
|
<varlistentry>
|
2003-07-28 02:14:43 +02:00
|
|
|
<term><varname>VERBOSITY</varname></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This variable can be set to the values <literal>default</>,
|
|
|
|
<literal>verbose</>, or <literal>terse</> to control the verbosity
|
|
|
|
of error reports.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2003-06-28 02:12:40 +02:00
|
|
|
</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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect3>
|
|
|
|
<title><acronym>SQL</acronym> Interpolation</title>
|
1999-11-04 23:07:57 +01:00
|
|
|
|
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
An additional useful feature of <application>psql</application>
|
|
|
|
variables is that you can substitute (<quote>interpolate</quote>)
|
2010-01-29 18:44:12 +01:00
|
|
|
them into regular <acronym>SQL</acronym> statements.
|
|
|
|
<application>psql</application> provides special facilities for
|
|
|
|
ensuring that values used as SQL literals and identifiers are
|
|
|
|
properly escaped. The syntax for interpolating a value without
|
|
|
|
any special escaping is again to prepend the variable name with a colon
|
2007-02-01 01:28:19 +01:00
|
|
|
(<literal>:</literal>):
|
* 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>
|
2010-01-29 18:44:12 +01:00
|
|
|
would then query the table <literal>my_table</literal>. Note that this
|
|
|
|
may be unsafe: the value of the variable is copied literally, so it can
|
|
|
|
even contain unbalanced quotes or backslash commands. You must make sure
|
|
|
|
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
|
|
|
|
safest to arrange for it to be escaped. To escape the value of
|
|
|
|
a variable as an SQL literal, write a colon followed by the variable
|
|
|
|
name in single quotes. To escape the value an SQL identifier, write
|
|
|
|
a colon followed by the variable name in double quotes. The previous
|
|
|
|
example would be more safely written this way:
|
|
|
|
<programlisting>
|
|
|
|
testdb=> <userinput>\set foo 'my_table'</userinput>
|
|
|
|
testdb=> <userinput>SELECT * FROM :"foo";</userinput>
|
|
|
|
</programlisting>
|
|
|
|
Variable interpolation will not be performed into quoted
|
|
|
|
<acronym>SQL</acronym> entities.
|
1999-11-04 23:07:57 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2008-05-08 02:27:57 +02:00
|
|
|
One possible use of this mechanism is to
|
2003-03-24 15:32:51 +01:00
|
|
|
copy the contents of a file into a table column. First load the file into a
|
2007-02-01 01:28:19 +01:00
|
|
|
variable and then proceed as above:
|
* 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.
|
2010-01-29 18:44:12 +01:00
|
|
|
psql 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
|
|
|
|
at interpolation (such as <literal>:name</literal>,
|
|
|
|
<literal>:'name'</literal>, or <literal>:"name"</literal>) is not
|
2010-02-19 04:50:03 +01:00
|
|
|
changed 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.
|
|
|
|
(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>.
|
2002-06-20 18:00:44 +02:00
|
|
|
The colon syntax for array slices and type casts are
|
|
|
|
<productname>PostgreSQL</productname> extensions, hence the
|
2010-01-29 18:44:12 +01:00
|
|
|
conflict. The colon 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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect3 id="APP-PSQL-prompting">
|
1999-11-04 23:07:57 +01:00
|
|
|
<title id="APP-PSQL-prompting-title">Prompting</title>
|
|
|
|
|
|
|
|
<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
|
|
|
|
issued when more input is expected during command input because the
|
|
|
|
command was not terminated with a semicolon or a quote was not closed.
|
2002-06-20 18:00:44 +02:00
|
|
|
Prompt 3 is issued when you run an <acronym>SQL</acronym>
|
|
|
|
<command>COPY</command> command and you are expected to type in the
|
2003-03-24 15:32:51 +01:00
|
|
|
row values 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>
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>%R</literal></term>
|
2004-06-18 08:14:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
In prompt 1 normally <literal>=</literal>, but <literal>^</literal> if
|
|
|
|
in single-line mode, and <literal>!</literal> if the session is
|
|
|
|
disconnected from the database (which can happen if
|
|
|
|
<command>\connect</command> fails). In prompt 2 the sequence is
|
|
|
|
replaced by <literal>-</literal>, <literal>*</literal>, a single quote,
|
2005-01-04 04:58:16 +01:00
|
|
|
a double quote, or a dollar sign, depending on whether
|
2004-06-18 08:14:31 +02:00
|
|
|
<application>psql</application> expects more input because the
|
|
|
|
command wasn't terminated yet, because you are inside a
|
|
|
|
<literal>/* ... */</literal> comment, or because you are inside
|
2005-01-04 04:58:16 +01:00
|
|
|
a quoted or dollar-escaped string. In prompt 3 the sequence doesn't
|
|
|
|
produce anything.
|
2004-06-18 08:14:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2003-06-28 02:12:40 +02:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
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
|
|
|
|
block, or <literal>*</> when in a transaction block, or
|
|
|
|
<literal>!</> when in a failed transaction block, or <literal>?</>
|
|
|
|
when the transaction state is indeterminate (for example, because
|
|
|
|
there is no connection).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<varlistentry>
|
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
|
|
|
|
<replaceable class="parameter">name</replaceable>. See the
|
|
|
|
section <xref linkend="APP-PSQL-variables"
|
|
|
|
endterm="APP-PSQL-variables-title"> for details.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
1999-11-04 23:07:57 +01:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
2004-01-20 20:49:34 +01:00
|
|
|
<varlistentry>
|
|
|
|
<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>
|
|
|
|
|
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
|
2002-06-20 18:00:44 +02:00
|
|
|
<literal>'%/%R%# '</literal> for prompts 1 and 2, and
|
|
|
|
<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
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect3>
|
2002-09-21 20:32:54 +02:00
|
|
|
<title>Command-Line Editing</title>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
|
|
|
<para>
|
2002-09-21 20:32:54 +02:00
|
|
|
<application>psql</application> supports the <application>Readline</application>
|
|
|
|
library for convenient line editing and retrieval. The command
|
2005-01-06 19:29:11 +01:00
|
|
|
history is automatically saved when <application>psql</application>
|
|
|
|
exits and is reloaded when
|
2002-06-20 18:00:44 +02:00
|
|
|
<application>psql</application> starts up. Tab-completion is also
|
|
|
|
supported, although the completion logic makes no claim to be an
|
2003-03-24 15:32:51 +01:00
|
|
|
<acronym>SQL</acronym> parser. If for some reason you do not like the tab completion, you
|
2005-01-04 04:58:16 +01:00
|
|
|
can turn it off 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>
|
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>
|
|
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Environment</title>
|
|
|
|
|
|
|
|
<variablelist>
|
2008-05-08 19:04:26 +02:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><envar>COLUMNS</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-05-16 18:59:05 +02:00
|
|
|
If <literal>\pset columns</> is zero, controls the
|
|
|
|
width for the <literal>wrapped</> format and width for determining
|
|
|
|
if wide output requires the pager.
|
2008-05-08 19:04:26 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><envar>PAGER</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If the query results do not fit on the screen, they are piped
|
|
|
|
through this command. Typical values are
|
|
|
|
<literal>more</literal> or <literal>less</literal>. The default
|
|
|
|
is platform-dependent. The use of the pager can be disabled by
|
|
|
|
using the <command>\pset</command> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><envar>PGDATABASE</envar></term>
|
|
|
|
<term><envar>PGHOST</envar></term>
|
|
|
|
<term><envar>PGPORT</envar></term>
|
|
|
|
<term><envar>PGUSER</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-06-01 18:23:08 +02:00
|
|
|
Default connection parameters (see <xref linkend="libpq-envars">).
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><envar>PSQL_EDITOR</envar></term>
|
|
|
|
<term><envar>EDITOR</envar></term>
|
|
|
|
<term><envar>VISUAL</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Editor used by the <command>\e</command> command. The variables
|
|
|
|
are examined in the order listed; the first that is set is used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><envar>SHELL</envar></term>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Command executed by the <command>\!</command> command.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<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>
|
2007-02-20 19:10:59 +01:00
|
|
|
This utility, like most other <productname>PostgreSQL</> utilities,
|
2007-03-26 19:23:37 +02:00
|
|
|
also uses the environment variables supported by <application>libpq</>
|
|
|
|
(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>
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2010-07-10 02:50:24 +02:00
|
|
|
Unless it is passed an <option>-X</option>
|
|
|
|
or <option>-c</option> option,
|
|
|
|
<application>psql</application> attempts to
|
2005-01-06 19:29:11 +01:00
|
|
|
read and execute commands from the system-wide
|
|
|
|
<filename>psqlrc</filename> file and the user's
|
2010-07-10 02:50:24 +02:00
|
|
|
<filename>~/.psqlrc</filename> file before starting up.
|
2005-01-06 19:29:11 +01:00
|
|
|
(On Windows, the user's startup file is named
|
2005-01-14 01:25:56 +01:00
|
|
|
<filename>%APPDATA%\postgresql\psqlrc.conf</filename>.)
|
2005-01-06 19:29:11 +01:00
|
|
|
See <filename><replaceable>PREFIX</>/share/psqlrc.sample</>
|
2004-06-18 08:14:31 +02:00
|
|
|
for information on setting up the system-wide file. It could be used
|
2004-04-22 03:53:37 +02:00
|
|
|
to set up the client or the server to taste (using the <command>\set
|
2002-07-28 17:22:21 +02:00
|
|
|
</command> and <command>SET</command> commands).
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
2005-01-06 19:29:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Both the system-wide <filename>psqlrc</filename> file and the user's
|
|
|
|
<filename>~/.psqlrc</filename> file can be made version-specific
|
|
|
|
by appending a dash and the <productname>PostgreSQL</productname>
|
|
|
|
release number, for example <filename>~/.psqlrc-&version;</filename>.
|
|
|
|
A matching version-specific file will be read in preference to a
|
|
|
|
non-version-specific file.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
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>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-07-03 05:37:17 +02:00
|
|
|
In an earlier life <application>psql</application> allowed the
|
|
|
|
first argument of a single-letter backslash command to start
|
|
|
|
directly after the command, without intervening whitespace.
|
|
|
|
As of <productname>PostgreSQL</productname> 8.4 this is no
|
|
|
|
longer allowed.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-07-03 05:37:17 +02:00
|
|
|
<application>psql</application> is only guaranteed to work smoothly
|
|
|
|
with servers of the same version. That does not mean other combinations
|
|
|
|
will fail outright, but subtle and not-so-subtle problems might come
|
|
|
|
up. Backslash commands are particularly likely to fail if the
|
|
|
|
server is of a newer version than <application>psql</> itself. However,
|
|
|
|
backslash commands of the <literal>\d</> family should work with
|
|
|
|
servers of versions back to 7.4, though not necessarily with servers
|
|
|
|
newer than <application>psql</> itself.
|
2002-07-28 17:22:21 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-01-14 23:18:03 +01:00
|
|
|
|
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
|
|
|
|
application</>. Since the Windows console windows use a different
|
|
|
|
encoding than the rest of the system, you must take special care
|
|
|
|
when using 8-bit characters within <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>
|
2006-10-23 20:10:32 +02:00
|
|
|
Set the console font to <literal>Lucida Console</>, because the
|
2004-12-27 21:13:48 +01:00
|
|
|
raster font does not work with the ANSI code page.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
2002-07-28 17:22:21 +02:00
|
|
|
<refsect1 id="APP-PSQL-examples">
|
1999-11-04 23:07:57 +01:00
|
|
|
<title id="APP-PSQL-examples-title">Examples</title>
|
|
|
|
|
|
|
|
<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>
|
2000-01-29 17:58:54 +01:00
|
|
|
Table "my_table"
|
|
|
|
Attribute | Type | Modifier
|
|
|
|
-----------+---------+--------------------
|
|
|
|
first | integer | not null default 0
|
|
|
|
second | text |
|
1999-11-04 23:07:57 +01:00
|
|
|
|
* 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.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset format unaligned</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Output format is unaligned.
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset fieldsep ","</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Field separator is ",".
|
2005-01-22 23:31:52 +01:00
|
|
|
peter@localhost testdb=> <userinput>\pset tuples_only</userinput>
|
1999-11-04 23:07:57 +01:00
|
|
|
Showing only tuples.
|
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
|
* 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
|
* 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
|
|
|
</para>
|
|
|
|
|
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>
|