Skip to content

Commit 6a36611

Browse files
committed
Forgot to back-patch earlier change to documentation for aggregate
ORDER BY clauses.
1 parent 5e84e1a commit 6a36611

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

doc/src/sgml/syntax.sgml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.147 2010/07/03 02:57:46 rhaas Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.147.2.1 2010/08/04 22:31:55 tgl Exp $ -->
22

33
<chapter id="sql-syntax">
44
<title>SQL Syntax</title>
@@ -1568,20 +1568,34 @@ sqrt(2)
15681568
unspecified order. In many cases this does not matter; for example,
15691569
<function>min</> produces the same result no matter what order it
15701570
receives the inputs in. However, some aggregate functions
1571-
(such as <function>array_agg</> and <function>xmlagg</>) produce
1571+
(such as <function>array_agg</> and <function>string_agg</>) produce
15721572
results that depend on the ordering of the input rows. When using
15731573
such an aggregate, the optional <replaceable>order_by_clause</> can be
15741574
used to specify the desired ordering. The <replaceable>order_by_clause</>
15751575
has the same syntax as for a query-level <literal>ORDER BY</> clause, as
15761576
described in <xref linkend="queries-order">, except that its expressions
15771577
are always just expressions and cannot be output-column names or numbers.
15781578
For example:
1579-
15801579
<programlisting>
15811580
SELECT array_agg(a ORDER BY b DESC) FROM table;
15821581
</programlisting>
15831582
</para>
15841583

1584+
<para>
1585+
When dealing with multiple-argument aggregate functions, note that the
1586+
<literal>ORDER BY</> clause goes after all the aggregate arguments.
1587+
For example, this:
1588+
<programlisting>
1589+
SELECT string_agg(a, ',' ORDER BY a) FROM table;
1590+
</programlisting>
1591+
not this:
1592+
<programlisting>
1593+
SELECT string_agg(a ORDER BY a, ',') FROM table; -- not what you want
1594+
</programlisting>
1595+
The latter syntax will be accepted, but <literal>','</> will be
1596+
treated as a (useless) sort key.
1597+
</para>
1598+
15851599
<para>
15861600
If <literal>DISTINCT</> is specified in addition to an
15871601
<replaceable>order_by_clause</>, then all the <literal>ORDER BY</>

0 commit comments

Comments
 (0)