Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
72150db0
Commit
72150db0
authored
14 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Add an example to clarify the use of ORDER BY in multiple-argument
aggregates. People seem to not get this right without help.
parent
14534353
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/src/sgml/syntax.sgml
+17
-3
17 additions, 3 deletions
doc/src/sgml/syntax.sgml
with
17 additions
and
3 deletions
doc/src/sgml/syntax.sgml
+
17
−
3
View file @
72150db0
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.14
8
2010/0
7/20 00:34:44 rhaas
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.14
9
2010/0
8/04 15:27:57 tgl
Exp $ -->
<chapter id="sql-syntax">
<title>SQL Syntax</title>
...
...
@@ -1567,7 +1567,7 @@ sqrt(2)
unspecified order. In many cases this does not matter; for example,
<function>min</> produces the same result no matter what order it
receives the inputs in. However, some aggregate functions
(such as <function>array_agg</> and <function>
xml
agg</>) produce
(such as <function>array_agg</> and <function>
string_
agg</>) produce
results that depend on the ordering of the input rows. When using
such an aggregate, the optional <replaceable>order_by_clause</> can be
used to specify the desired ordering. The <replaceable>order_by_clause</>
...
...
@@ -1575,12 +1575,26 @@ sqrt(2)
described in <xref linkend="queries-order">, except that its expressions
are always just expressions and cannot be output-column names or numbers.
For example:
<programlisting>
SELECT array_agg(a ORDER BY b DESC) FROM table;
</programlisting>
</para>
<para>
When dealing with multiple-argument aggregate functions, note that the
<literal>ORDER BY</> clause goes after all the aggregate arguments.
For example, this:
<programlisting>
SELECT string_agg(a, ',' ORDER BY a) FROM table;
</programlisting>
not this:
<programlisting>
SELECT string_agg(a ORDER BY a, ',') FROM table; -- not what you want
</programlisting>
The latter syntax will be accepted, but <literal>','</> will be
treated as a (useless) sort key.
</para>
<para>
If <literal>DISTINCT</> is specified in addition to an
<replaceable>order_by_clause</>, then all the <literal>ORDER BY</>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment