mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Improve documentation for \crosstabview.
Fix misleading syntax summary (there cannot be a space between colH and scolH). Provide a link from the existing crosstab() function's documentation to \crosstabview. Copy-edit the command's description. Christoph Berg and Tom Lane
This commit is contained in:
@ -989,106 +989,78 @@ testdb=>
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
|
<varlistentry id="APP-PSQL-meta-commands-crosstabview">
|
||||||
<term><literal>\crosstabview [
|
<term><literal>\crosstabview [
|
||||||
<replaceable class="parameter">colV</replaceable>
|
<replaceable class="parameter">colV</replaceable>
|
||||||
<replaceable class="parameter">colH</replaceable>
|
<replaceable class="parameter">colH</replaceable>[:<replaceable class="parameter">scolH</replaceable>]
|
||||||
[:<replaceable class="parameter">scolH</replaceable>]
|
|
||||||
[<replaceable class="parameter">colD</replaceable>]
|
[<replaceable class="parameter">colD</replaceable>]
|
||||||
] </literal></term>
|
] </literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Execute the current query buffer (like <literal>\g</literal>) and shows
|
Executes the current query buffer (like <literal>\g</literal>) and
|
||||||
the results inside a crosstab grid.
|
shows the results in a crosstab grid.
|
||||||
The query must return at least three columns.
|
The query must return at least three columns.
|
||||||
The output column <replaceable class="parameter">colV</replaceable>
|
The output column identified by <replaceable class="parameter">colV</>
|
||||||
becomes a vertical header
|
becomes a vertical header and the output column identified by
|
||||||
and the output column <replaceable class="parameter">colH</replaceable>
|
<replaceable class="parameter">colH</replaceable>
|
||||||
becomes a horizontal header, optionally sorted by ranking data obtained
|
becomes a horizontal header, optionally sorted by ranking data obtained
|
||||||
from <replaceable class="parameter">scolH</replaceable>.
|
from column <replaceable class="parameter">scolH</replaceable>.
|
||||||
<replaceable class="parameter">colD</replaceable>
|
<replaceable class="parameter">colD</replaceable> identifies
|
||||||
is the output column to project into the grid. If this is not
|
the output column to display within the grid.
|
||||||
|
If <replaceable class="parameter">colD</replaceable> is not
|
||||||
specified and there are exactly three columns in the result set,
|
specified and there are exactly three columns in the result set,
|
||||||
the column that isn't
|
the column that is neither
|
||||||
<replaceable class="parameter">colV</replaceable> nor
|
<replaceable class="parameter">colV</replaceable> nor
|
||||||
<replaceable class="parameter">colH</replaceable>
|
<replaceable class="parameter">colH</replaceable>
|
||||||
is displayed; if there are more columns, an error is thrown.
|
is displayed; if there are more columns, an error is reported.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
All columns can be refered to by their position (starting at 1), or by
|
Each column specification can be a column number (starting at 1) or
|
||||||
their name. Normal case folding and quoting rules apply on column
|
a column name. The usual SQL case folding and quoting rules apply to
|
||||||
names. By default,
|
column names. If omitted,
|
||||||
<replaceable class="parameter">colV</replaceable> corresponds to column 1
|
<replaceable class="parameter">colV</replaceable> is taken as column 1
|
||||||
and <replaceable class="parameter">colH</replaceable> to column 2.
|
and <replaceable class="parameter">colH</replaceable> as column 2.
|
||||||
A query having only one output column cannot be viewed in crosstab, and
|
|
||||||
<replaceable class="parameter">colH</replaceable> must differ from
|
<replaceable class="parameter">colH</replaceable> must differ from
|
||||||
<replaceable class="parameter">colV</replaceable>.
|
<replaceable class="parameter">colV</replaceable>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The vertical header, displayed as the leftmost column,
|
The vertical header, displayed as the leftmost column, contains the
|
||||||
contains the deduplicated values found in
|
values found in column <replaceable class="parameter">colV</>, in the
|
||||||
column <replaceable class="parameter">colV</replaceable>, in the same
|
same order as in the query results, but with duplicates removed.
|
||||||
order as in the query results.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The horizontal header, displayed as the first row,
|
The horizontal header, displayed as the first row, contains the values
|
||||||
contains the deduplicated values found in
|
found in column <replaceable class="parameter">colH</replaceable>,
|
||||||
column <replaceable class="parameter">colH</replaceable>, in
|
with duplicates removed. By default, these appear in the same order
|
||||||
the order of appearance in the query results.
|
as in the query results. But if the
|
||||||
If specified, the optional <replaceable class="parameter">scolH</replaceable>
|
optional <replaceable class="parameter">scolH</> argument is given, it
|
||||||
argument refers to a column whose values should be integer numbers
|
identifies a column whose values must be integer numbers, and the
|
||||||
by which <replaceable class="parameter">colH</replaceable> will be sorted
|
values from <replaceable class="parameter">colH</replaceable> will
|
||||||
to be positioned in the horizontal header.
|
appear in the horizontal header sorted according to the
|
||||||
|
corresponding <replaceable class="parameter">scolH</> values.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Inside the crosstab grid,
|
Inside the crosstab grid, for each distinct value <literal>x</literal>
|
||||||
given a query output with <literal>N</literal> columns
|
of <replaceable class="parameter">colH</replaceable> and each distinct
|
||||||
(including <replaceable class="parameter">colV</replaceable> and
|
value <literal>y</literal>
|
||||||
<replaceable class="parameter">colH</replaceable>),
|
of <replaceable class="parameter">colV</replaceable>, the cell located
|
||||||
for each distinct value <literal>x</literal> of
|
at the intersection <literal>(x,y)</literal> contains the value of
|
||||||
<replaceable class="parameter">colH</replaceable>
|
the <literal>colD</literal> column in the query result row for which
|
||||||
and each distinct value <literal>y</literal> of
|
the value of <replaceable class="parameter">colH</replaceable>
|
||||||
<replaceable class="parameter">colV</replaceable>,
|
is <literal>x</literal> and the value
|
||||||
the contents of a cell located at the intersection
|
of <replaceable class="parameter">colV</replaceable>
|
||||||
<literal>(x,y)</literal> is determined by these rules:
|
is <literal>y</>. If there is no such row, the cell is empty. If
|
||||||
<itemizedlist>
|
there are multiple such rows, an error is reported.
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
if there is no corresponding row in the query results such that the
|
|
||||||
value for <replaceable class="parameter">colH</replaceable>
|
|
||||||
is <literal>x</literal> and the value
|
|
||||||
for <replaceable class="parameter">colV</replaceable>
|
|
||||||
is <literal>y</literal>, the cell is empty.
|
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
if there is exactly one row such that the value
|
|
||||||
for <replaceable class="parameter">colH</replaceable>
|
|
||||||
is <literal>x</literal> and the value
|
|
||||||
for <replaceable class="parameter">colV</replaceable>
|
|
||||||
is <literal>y</literal>, then the <literal>colD</literal> column
|
|
||||||
is displayed.
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
if there are several such rows, an error is thrown.
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>\d[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
<term><literal>\d[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
|
||||||
|
|
||||||
|
@ -293,6 +293,14 @@ AS ct(row_name text, category_1 text, category_2 text, category_3 text);
|
|||||||
required <literal>FROM</> clause in a view definition.
|
required <literal>FROM</> clause in a view definition.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<note>
|
||||||
|
<para>
|
||||||
|
See also the <command><link linkend="APP-PSQL-meta-commands-crosstabview">\crosstabview</link></command>
|
||||||
|
command in <application>psql</>, which provides functionality similar
|
||||||
|
to <function>crosstab()</>.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
|
||||||
</sect3>
|
</sect3>
|
||||||
|
|
||||||
<sect3>
|
<sect3>
|
||||||
|
Reference in New Issue
Block a user