Forgot to back-patch earlier change to documentation for aggregate
authorTom Lane
Wed, 4 Aug 2010 22:31:55 +0000 (22:31 +0000)
committerTom Lane
Wed, 4 Aug 2010 22:31:55 +0000 (22:31 +0000)
ORDER BY clauses.

doc/src/sgml/syntax.sgml

index bf63425a719a042cc7980218cf714e8b59ca303f..0c1f2068b1860e325f1b15f0f84d28935dd1073a 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  SQL Syntax
@@ -1568,7 +1568,7 @@ sqrt(2)
     unspecified order.  In many cases this does not matter; for example,
     min produces the same result no matter what order it
     receives the inputs in.  However, some aggregate functions
-    (such as array_agg and xmlagg) produce
+    (such as array_agg and string_agg) produce
     results that depend on the ordering of the input rows.  When using
     such an aggregate, the optional order_by_clause can be
     used to specify the desired ordering.  The order_by_clause
@@ -1576,12 +1576,26 @@ sqrt(2)
     described in , except that its expressions
     are always just expressions and cannot be output-column names or numbers.
     For example:
-
 
 SELECT array_agg(a ORDER BY b DESC) FROM table;
 
    
 
+   
+    When dealing with multiple-argument aggregate functions, note that the
+    ORDER BY clause goes after all the aggregate arguments.
+    For example, this:
+
+SELECT string_agg(a, ',' ORDER BY a) FROM table;
+
+    not this:
+
+SELECT string_agg(a ORDER BY a, ',') FROM table;  -- not what you want
+
+    The latter syntax will be accepted, but ',' will be
+    treated as a (useless) sort key.
+   
+
    
     If DISTINCT is specified in addition to an
     order_by_clause, then all the ORDER BY