### Get Postgres Tips and Tricks

Subscribe to get advanced Postgres how-tos.

2 The SQL Language : 2.4 Functions and Operators : 2.4.11 Aggregate Functions

2.4.11 Aggregate FunctionsAggregate functions compute a single result value from a set of input values. The built-in aggregate functions are listed in the following tables.

NUMBER for any integer type, DOUBLE PRECISION for a floating-point argument, otherwise the same as the argument data type BIGINT for SMALLINT or INTEGER arguments, NUMBER for BIGINT arguments, DOUBLE PRECISION for floating-point arguments, otherwise the same as the argument data type It should be noted that except for COUNT, these functions return a null value when no rows are selected. In particular, SUM of no rows returns null, not zero as one might expect. The COALESCE function may be used to substitute zero for null when necessary.The following table shows the aggregate functions typically used in statistical analysis. (These are separated out merely to avoid cluttering the listing of more-commonly-used aggregates.) Where the description mentions N, it means the number of input rows for which all the input expressions are non-null. In all cases, null is returned if the computation is meaningless, for example when N is zero.

Historic alias for STDDEV_SAMP Historical alias for VAR_SAMP

2 The SQL Language : 2.4 Functions and Operators : 2.4.11 Aggregate Functions