@ -68,8 +68,8 @@ PostgreSQL documentation
<listitem>
<listitem>
<para>
<para>
Switches to unaligned output mode. (The default output mode is
Switches to unaligned output mode. (The default output mode is
otherwise aligned.) This is equivalent to <command>\pset format
<literal>aligned</literal>.) This is equivalent to
unaligned</command>.
<command>\pset format unaligned</command>.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
@ -151,6 +151,16 @@ EOF
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><option>--csv</option></term>
<listitem>
<para>
Switches to <acronym>CSV</acronym> (Comma-Separated Values) output
mode. This is equivalent to <command>\pset format csv</command>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-d <replaceable class="parameter">dbname</replaceable></option></term>
<term><option>-d <replaceable class="parameter">dbname</replaceable></option></term>
<term><option>--dbname=<replaceable class="parameter">dbname</replaceable></option></term>
<term><option>--dbname=<replaceable class="parameter">dbname</replaceable></option></term>
@ -270,8 +280,8 @@ EOF
<term><option>--html</option></term>
<term><option>--html</option></term>
<listitem>
<listitem>
<para>
<para>
Turn on <acronym>HTML</acronym> tabular output. This is
Switches to <acronym>HTML</acronym> output mode. This is
equivalent to <literal>\pset format html</literal > or the
equivalent to <command>\pset format html</command > or the
<command>\H</command> command.
<command>\H</command> command.
</para>
</para>
</listitem>
</listitem>
@ -2520,6 +2530,19 @@ lo_import 152801
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><literal>csv_fieldsep</literal></term>
<listitem>
<para>
Specifies the field separator to be used in
<acronym>CSV</acronym> output format. If the separator character
appears in a field's value, that field is output within double
quotes, following standard <acronym>CSV</acronym> rules.
The default is a comma.
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry>
<term><literal>expanded</literal> (or <literal>x</literal>)</term>
<term><literal>expanded</literal> (or <literal>x</literal>)</term>
<listitem>
<listitem>
@ -2547,8 +2570,8 @@ lo_import 152801
<listitem>
<listitem>
<para>
<para>
Specifies the field separator to be used in unaligned output
Specifies the field separator to be used in unaligned output
format. That way one can create, for example, tab- or
format. That way one can create, for example, tab-separated
comma-separated output, which other programs might prefer. To
output, which other programs might prefer. To
set a tab as field separator, type <literal>\pset fieldsep
set a tab as field separator, type <literal>\pset fieldsep
'\t'</literal>. The default field separator is
'\t'</literal>. The default field separator is
<literal>'|'</literal> (a vertical bar).
<literal>'|'</literal> (a vertical bar).
@ -2585,22 +2608,48 @@ lo_import 152801
<listitem>
<listitem>
<para>
<para>
Sets the output format to one of <literal>aligned</literal>,
Sets the output format to one of <literal>aligned</literal>,
<literal>asciidoc</literal>, <literal>html</literal>,
<literal>asciidoc</literal>,
<literal>latex</literal> (uses <literal>tabular</literal>),
<literal>csv</literal>,
<literal>html</literal>,
<literal>latex</literal>,
<literal>latex-longtable</literal>, <literal>troff-ms</literal>,
<literal>latex-longtable</literal>, <literal>troff-ms</literal>,
<literal>unaligned</literal>, or <literal>wrapped</literal>.
<literal>unaligned</literal>, or <literal>wrapped</literal>.
Unique abbreviations are allowed.
Unique abbreviations are allowed.
</para>
</para>
<para><literal>aligned</literal> format is the standard,
human-readable, nicely formatted text output; this is the default.
</para>
<para><literal>unaligned</literal> format writes all columns of a row on one
<para><literal>unaligned</literal> format writes all columns of a row on one
line, separated by the currently active field separator. This
line, separated by the currently active field separator. This
is useful for creating output that might be intended to be read
is useful for creating output that might be intended to be read
in by other programs (for example, tab-separated or comma-separated
in by other programs, for example, tab-separated or comma-separated
format).
format. However, the field separator character is not treated
specially if it appears in a column's value;
so <acronym>CSV</acronym> format may be better suited for such
purposes.
</para>
</para>
<para><literal>aligned</literal> format is the standard, human-readable,
<para><literal>csv</literal> format
nicely formatted text output; this is the default.
<indexterm>
<primary>CSV (Comma-Separated Values) format</primary>
<secondary>in psql</secondary>
</indexterm>
writes column values separated by commas, applying the quoting
rules described in
<ulink url="https://tools.ietf.org/html/rfc4180">RFC 4180</ulink>.
This output is compatible with the CSV format of the server's
<command>COPY</command> command.
A header line with column names is generated unless
the <literal>tuples_only</literal> parameter is
<literal>on</literal>. Titles and footers are not printed.
Each row is terminated by the system-dependent end-of-line character,
which is typically a single newline (<literal>\n</literal>) for
Unix-like systems or a carriage return and newline sequence
(<literal>\r\n</literal>) for Microsoft Windows.
Field separator characters other than comma can be selected with
<command>\pset csv_fieldsep</command>.
</para>
</para>
<para><literal>wrapped</literal> format is like <literal>aligned</literal> but wraps
<para><literal>wrapped</literal> format is like <literal>aligned</literal> but wraps
@ -2620,8 +2669,12 @@ lo_import 152801
language. They are not complete documents! This might not be
language. They are not complete documents! This might not be
necessary in <acronym>HTML</acronym>, but in
necessary in <acronym>HTML</acronym>, but in
<application>LaTeX</application> you must have a complete
<application>LaTeX</application> you must have a complete
document wrapper. <literal>latex-longtable</literal>
document wrapper.
also requires the <application>LaTeX</application>
The <literal>latex</literal> format
uses <application>LaTeX</application>'s <literal>tabular</literal>
environment.
The <literal>latex-longtable</literal> format
requires the <application>LaTeX</application>
<literal>longtable</literal> and <literal>booktabs</literal> packages.
<literal>longtable</literal> and <literal>booktabs</literal> packages.
</para>
</para>
</listitem>
</listitem>
@ -4588,17 +4641,24 @@ first second
peter@localhost testdb=> <userinput>\pset border 1</userinput>
peter@localhost testdb=> <userinput>\pset border 1</userinput>
Border style is 1.
Border style is 1.
peter@localhost testdb=> <userinput>\pset format unaligned</userinput>
peter@localhost testdb=> <userinput>\pset format csv</userinput>
Output format is unaligned.
Output format is csv.
peter@localhost testdb=> <userinput>\pset fieldsep ","</userinput>
Field separator is ",".
peter@localhost testdb=> <userinput>\pset tuples_only</userinput>
peter@localhost testdb=> <userinput>\pset tuples_only</userinput>
Showing only tuples .
Tuples only is on.
peter@localhost testdb=> <userinput>SELECT second, first FROM my_table;</userinput>
peter@localhost testdb=> <userinput>SELECT second, first FROM my_table;</userinput>
one,1
one,1
two,2
two,2
three,3
three,3
four,4
four,4
peter@localhost testdb=> <userinput>\pset format unaligned</userinput>
Output format is unaligned.
peter@localhost testdb=> <userinput>\pset fieldsep '\t'</userinput>
Field separator is " ".
peter@localhost testdb=> <userinput>SELECT second, first FROM my_table;</userinput>
one 1
two 2
three 3
four 4
</programlisting>
</programlisting>
Alternatively, use the short commands:
Alternatively, use the short commands:
<programlisting>
<programlisting>