|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.153 2010/08/13 01:12:38 rhaas Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.154 2010/09/01 18:22:29 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="sql-syntax">
|
4 | 4 | <title>SQL Syntax</title>
|
@@ -1541,23 +1541,29 @@ sqrt(2)
|
1541 | 1541 |
|
1542 | 1542 | <para>
|
1543 | 1543 | The first form of aggregate expression invokes the aggregate
|
1544 |
| - across all input rows for which the given expression(s) yield |
1545 |
| - non-null values. (Actually, it is up to the aggregate function |
1546 |
| - whether to ignore null values or not — but all the standard ones do.) |
| 1544 | + once for each input row. |
1547 | 1545 | The second form is the same as the first, since
|
1548 |
| - <literal>ALL</literal> is the default. The third form invokes the |
1549 |
| - aggregate for all distinct values of the expressions found |
1550 |
| - in the input rows (ignoring nulls if the function chooses to do so). |
1551 |
| - The last form invokes the aggregate once for |
1552 |
| - each input row regardless of null or non-null values; since no |
| 1546 | + <literal>ALL</literal> is the default. |
| 1547 | + The third form invokes the aggregate once for each distinct value |
| 1548 | + of the expression (or distinct set of values, for multiple expressions) |
| 1549 | + found in the input rows. |
| 1550 | + The last form invokes the aggregate once for each input row; since no |
1553 | 1551 | particular input value is specified, it is generally only useful
|
1554 | 1552 | for the <function>count(*)</function> aggregate function.
|
1555 | 1553 | </para>
|
1556 | 1554 |
|
| 1555 | + <para> |
| 1556 | + Most aggregate functions ignore null inputs, so that rows in which |
| 1557 | + one or more of the expression(s) yield null are discarded. This |
| 1558 | + can be assumed to be true, unless otherwise specified, for all |
| 1559 | + built-in aggregates. |
| 1560 | + </para> |
| 1561 | + |
1557 | 1562 | <para>
|
1558 | 1563 | For example, <literal>count(*)</literal> yields the total number
|
1559 | 1564 | of input rows; <literal>count(f1)</literal> yields the number of
|
1560 |
| - input rows in which <literal>f1</literal> is non-null; |
| 1565 | + input rows in which <literal>f1</literal> is non-null, since |
| 1566 | + <function>count</> ignores nulls; and |
1561 | 1567 | <literal>count(distinct f1)</literal> yields the number of
|
1562 | 1568 | distinct non-null values of <literal>f1</literal>.
|
1563 | 1569 | </para>
|
|
0 commit comments