@@ -1539,7 +1539,7 @@ Not defined by this name. Implements the intersection operator '#'
1539
1539
1540
1540
<para>
1541
1541
<firstterm>Aggregate functions</firstterm> allow the generation of simple
1542
- statistics about the values of particular columns over the selected set
1542
+ statistics about the values of given expressions over the selected set
1543
1543
of rows.
1544
1544
<!--
1545
1545
See also <xref linkend="sql" endterm="aggregates-tutorial"> and
@@ -1556,13 +1556,15 @@ Not defined by this name. Implements the intersection operator '#'
1556
1556
<title>Aggregate Functions</title>
1557
1557
<tgroup cols="4">
1558
1558
<thead>
1559
+
1559
1560
<row>
1560
1561
<entry>Function</entry>
1561
1562
<entry>Returns</entry>
1562
1563
<entry>Description</entry>
1563
1564
<entry>Example</entry>
1564
1565
<entry>Notes</entry>
1565
1566
</row>
1567
+
1566
1568
</thead>
1567
1569
<tbody>
1568
1570
<row>
@@ -1572,45 +1574,85 @@ Not defined by this name. Implements the intersection operator '#'
1572
1574
<entry>COUNT(*)</entry>
1573
1575
<entry></entry>
1574
1576
</row>
1577
+
1575
1578
<row>
1576
- <entry>COUNT(<replaceable class="parameter">column-name </replaceable>)</entry>
1579
+ <entry>COUNT(<replaceable class="parameter">expression </replaceable>)</entry>
1577
1580
<entry>int4</entry>
1578
- <entry>Counts the selected rows for which the value of <replaceable class="parameter">column-name</replaceable> is not NULL.</entry>
1581
+ <entry>Counts the selected rows for which the value of
1582
+ <replaceable class="parameter">expression</replaceable> is not
1583
+ NULL.</entry>
1579
1584
<entry>COUNT(age)</entry>
1580
1585
<entry></entry>
1581
1586
</row>
1587
+
1582
1588
<row>
1583
- <entry>SUM(<replaceable class="parameter">column-name </replaceable>)</entry>
1584
- <entry>Same as the data type of the column being summed.</entry>
1585
- <entry>Finds the total obtained by adding the values of <replaceable class="parameter">column-name </replaceable> across all selected rows.</entry>
1589
+ <entry>SUM(<replaceable class="parameter">expression </replaceable>)</entry>
1590
+ <entry>Depends on the data type being summed.</entry>
1591
+ <entry>Finds the total obtained by adding the values of <replaceable class="parameter">expression </replaceable> across all selected rows.</entry>
1586
1592
<entry>SUM(hours)</entry>
1587
- <entry>Summation is supported on the following data types: int8, int4, int2, float4, float8, money, interval, numeric</entry>
1593
+ <entry>Summation is supported on the following data types: int8, int4,
1594
+ int2, float4, float8, money, interval, numeric. The result is numeric
1595
+ for any integer type, float8 for either float4 or float8 input,
1596
+ otherwise the same as the input data type.</entry>
1588
1597
</row>
1598
+
1589
1599
<row>
1590
- <entry>MAX(<replaceable class="parameter">column-name </replaceable>)</entry>
1591
- <entry>Same as the data type of the column whose maximum value is sought .</entry>
1592
- <entry>The maximum value of <replaceable class="parameter">column-name </replaceable> across all selected rows.</entry>
1600
+ <entry>MAX(<replaceable class="parameter">expression </replaceable>)</entry>
1601
+ <entry>Same as the data type of the input expression .</entry>
1602
+ <entry>The maximum value of <replaceable class="parameter">expression </replaceable> across all selected rows.</entry>
1593
1603
<entry>MAX(age)</entry>
1594
1604
<entry>Finding the maximum value is supported on the following data types: int8, int4, int2, float4, float8, date, time, timetz, money, timestamp, interval, text, numeric.</entry>
1595
1605
</row>
1606
+
1596
1607
<row>
1597
- <entry>MIN(<replaceable class="parameter">column-name </replaceable>)</entry>
1598
- <entry>same as the data type of the column whose minimum value is sought .</entry>
1599
- <entry>The minimum value of <replaceable class="parameter">column-name </replaceable> across all selected rows.</entry>
1608
+ <entry>MIN(<replaceable class="parameter">expression </replaceable>)</entry>
1609
+ <entry>Same as the data type of the input expression .</entry>
1610
+ <entry>The minimum value of <replaceable class="parameter">expression </replaceable> across all selected rows.</entry>
1600
1611
<entry>MIN(age)</entry>
1601
1612
<entry>Finding the minimum value is supported on the following data types: int8, int4, int2, float4, float8, date, time, timetz, money, timestamp, interval, text, numeric.</entry>
1602
1613
</row>
1614
+
1603
1615
<row>
1604
- <entry>AVG(<replaceable class="parameter">column-name</replaceable>)</entry>
1605
- <entry>Same as the data type of the column being averaged.</entry>
1606
- <entry>The average (mean) of the values in the given column across all selected rows.</entry>
1607
- <entry>AVG(age)</entry>
1608
- <entry>Finding the mean value is supported on the following data types: int8, int4, int2, float4, float8, money, interval, numeric. Note that as the return type is the same as that of the data being averaged, using AVG() on discrete data will give a rounded result.</entry>
1616
+ <entry>AVG(<replaceable class="parameter">expression</replaceable>)</entry>
1617
+ <entry>Depends on the data type being averaged.</entry>
1618
+ <entry>The average (mean) of the given values across all selected rows.</entry>
1619
+ <entry>AVG(age+1)</entry>
1620
+ <entry>Finding the mean value is supported on the following data
1621
+ types: int8, int4, int2, float4, float8, interval, numeric. The
1622
+ result is numeric for any integer type, float8 for either float4 or
1623
+ float8 input, otherwise the same as the input data type.</entry>
1609
1624
</row>
1625
+
1626
+ <row>
1627
+ <entry>VARIANCE(<replaceable class="parameter">expression</replaceable>)</entry>
1628
+ <entry>Depends on the input data type.</entry>
1629
+ <entry>The sample variance of the given values.</entry>
1630
+ <entry>VARIANCE(reading)</entry>
1631
+ <entry>Finding the variance is supported on the following data
1632
+ types: int8, int4, int2, float4, float8, numeric. The result is
1633
+ float8 for float4 or float8 input, otherwise numeric.</entry>
1634
+ </row>
1635
+
1636
+ <row>
1637
+ <entry>STDDEV(<replaceable class="parameter">expression</replaceable>)</entry>
1638
+ <entry>Depends on the input data type.</entry>
1639
+ <entry>The sample standard deviation of the given values.</entry>
1640
+ <entry>STDDEV(reading)</entry>
1641
+ <entry>Finding the standard deviation is supported on the following
1642
+ data types: int8, int4, int2, float4, float8, numeric. The result is
1643
+ float8 for float4 or float8 input, otherwise numeric.</entry>
1644
+ </row>
1645
+
1610
1646
</tbody>
1611
1647
</tgroup>
1612
1648
</table>
1613
1649
</para>
1650
+
1651
+ <para>
1652
+ It should be noted that except for COUNT, these functions return NULL
1653
+ when no rows are selected. In particular, SUM of no rows returns NULL,
1654
+ not zero as one might expect.
1655
+ </para>
1614
1656
</sect1>
1615
1657
</chapter>
1616
1658
0 commit comments