public inbox for [email protected]
help / color / mirror / Atom feedAggregate expression syntax
3+ messages / 3 participants
[nested] [flat]
* Aggregate expression syntax
@ 2015-01-20 13:50 Thom Brown <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Thom Brown @ 2015-01-20 13:50 UTC (permalink / raw)
To: pgsql-docs
Hi all,
Looking at the syntax for aggregate expressions in the docs, it seems the
first three forms could perhaps be merged since the ALL and DISTINCT
keywords are effectively optional.
Currently:
aggregate_name (expression [ , ... ] [ order_by_clause ] ) [ FILTER ( WHERE
filter_clause ) ]
aggregate_name (ALL expression [ , ... ] [ order_by_clause ] ) [ FILTER (
WHERE filter_clause ) ]
aggregate_name (DISTINCT expression [ , ... ] [ order_by_clause ] ) [
FILTER ( WHERE filter_clause ) ]
Proposed:
aggregate_name ( [ ALL | DISTINCT ] expression [ , ... ] [ order_by_clause
] ) [ FILTER ( WHERE filter_clause ) ]
I've also found a precedent for this on the SELECT statement page:
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
Patch attached with the proposed change.
Opinions?
Thom
--
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs
Attachments:
[text/x-patch] agg_exp_docs.patch (2.5K, 3-agg_exp_docs.patch)
download | inline diff:
diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml
index 4b81b08..4f8a43b 100644
--- a/doc/src/sgml/syntax.sgml
+++ b/doc/src/sgml/syntax.sgml
@@ -1574,9 +1574,7 @@ sqrt(2)
syntax of an aggregate expression is one of the following:
<synopsis>
-<replaceable>aggregate_name</replaceable> (<replaceable>expression</replaceable> [ , ... ] [ <replaceable>order_by_clause</replaceable> ] ) [ FILTER ( WHERE <replaceable>filter_clause</replaceable> ) ]
-<replaceable>aggregate_name</replaceable> (ALL <replaceable>expression</replaceable> [ , ... ] [ <replaceable>order_by_clause</replaceable> ] ) [ FILTER ( WHERE <replaceable>filter_clause</replaceable> ) ]
-<replaceable>aggregate_name</replaceable> (DISTINCT <replaceable>expression</replaceable> [ , ... ] [ <replaceable>order_by_clause</replaceable> ] ) [ FILTER ( WHERE <replaceable>filter_clause</replaceable> ) ]
+<replaceable>aggregate_name</replaceable> ( [ ALL | DISTINCT ] <replaceable>expression</replaceable> [ , ... ] [ <replaceable>order_by_clause</replaceable> ] ) [ FILTER ( WHERE <replaceable>filter_clause</replaceable> ) ]
<replaceable>aggregate_name</replaceable> ( * ) [ FILTER ( WHERE <replaceable>filter_clause</replaceable> ) ]
<replaceable>aggregate_name</replaceable> ( [ <replaceable>expression</replaceable> [ , ... ] ] ) WITHIN GROUP ( <replaceable>order_by_clause</replaceable> ) [ FILTER ( WHERE <replaceable>filter_clause</replaceable> ) ]
</synopsis>
@@ -1591,14 +1589,12 @@ sqrt(2)
</para>
<para>
- The first form of aggregate expression invokes the aggregate
- once for each input row.
- The second form is the same as the first, since
- <literal>ALL</literal> is the default.
- The third form invokes the aggregate once for each distinct value
- of the expression (or distinct set of values, for multiple expressions)
- found in the input rows.
- The fourth form invokes the aggregate once for each input row; since no
+ The first form of aggregate expression with the <literal>ALL</literal>
+ keyword (the default) invokes the aggregate once for each input row.
+ Specifying <literal>DISTINCT</literal> invokes the aggregate once for
+ each distinct value of the expression (or distinct set of values, for
+ multiple expressions) found in the input rows.
+ The second form invokes the aggregate once for each input row; since no
particular input value is specified, it is generally only useful
for the <function>count(*)</function> aggregate function.
The last form is used with <firstterm>ordered-set</> aggregate
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Aggregate expression syntax
@ 2015-01-20 14:48 Tom Lane <[email protected]>
parent: Thom Brown <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2015-01-20 14:48 UTC (permalink / raw)
To: Thom Brown <[email protected]>; +Cc: pgsql-docs
Thom Brown <[email protected]> writes:
> Looking at the syntax for aggregate expressions in the docs, it seems the
> first three forms could perhaps be merged since the ALL and DISTINCT
> keywords are effectively optional.
Dunno, just seems harder to read to me...
regards, tom lane
--
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Aggregate expression syntax
@ 2015-01-20 17:44 David G Johnston <[email protected]>
parent: Tom Lane <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: David G Johnston @ 2015-01-20 17:44 UTC (permalink / raw)
To: pgsql-docs
Tom Lane-2 wrote
> Thom Brown <
> thom@
> > writes:
>> Looking at the syntax for aggregate expressions in the docs, it seems the
>> first three forms could perhaps be merged since the ALL and DISTINCT
>> keywords are effectively optional.
>
> Dunno, just seems harder to read to me...
I'm generally for making the syntax part more succinct and addressing
learning concerns with examples. The extra noise that needs to be filtered
out when trying to figure out why different structures exist makes it
difficult to read too.
That said, having at least a bare-minimum expression would be helpful:
aggregate_name ( expression )
And now decide whether to have a combined syntax block or keep building
things up like:
aggregate_name ( [ ALL | DISTINCT ] expression [ , ... ] [ order_by_clause]
)
aggregate_name ( argument_clause ) [ FILTER ( WHERE [ filter_clause ] ) ]
argument_clause := " [ ALL | DISTINCT ] expression [ , ... ] [
order_by_clause ] "
If we are going to repeat long and complex parts of the syntax naming them
will make reading subsequent syntax expressions easier and provide semantic
meaning to the reader. The existing forms, while correct, are repetitive
and that is what is being targeted but combining them into a single syntax
block. But if that is too hard to read and understand then maybe some other
means of simplification, like my example above, would work better.
David J.
--
View this message in context: http://postgresql.nabble.com/Aggregate-expression-syntax-tp5834726p5834768.html
Sent from the PostgreSQL - docs mailing list archive at Nabble.com.
--
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2015-01-20 17:44 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20 13:50 Aggregate expression syntax Thom Brown <[email protected]>
2015-01-20 14:48 ` Tom Lane <[email protected]>
2015-01-20 17:44 ` David G Johnston <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox