Author: Written by Isaac Wilcox
<isaac@azartmedia.com>on 2000-06-16
Aggregate functions compute a single result value from a set of input values. The special syntax considerations for aggregate functions are explained in Section 1.3.5. Consult the PostgreSQL Tutorial for additional introductory information.
Table 4-30. Aggregate Functions
It should be noted that except for COUNT, these functions return NULL when no rows
are selected. In particular, SUM of
no rows returns NULL, not zero as one might expect. COALESCE may be used to substitute zero for
NULL when necessary.
I don\'t know so much sql, but a first() aggregate makes no sense to me.
If your query is unordered (no ORDER BY), first() would be undefined (because the order of the tuples in the group would be undefined),
if it is ordered first() would be either max() or min(), yo you can use these.
The only case when it can be useful is when there is an ordering of the tuples in a group defined by a multifield key (and then an expression for maxing or mining would still be possible, just more inconvenient to write), or when the key field type cannot be maxed or mined or converted to a supported type for max and min.
I guess sql is meant to operate on sets, not lists, and so first() and last() are a bit unnatural.