Appearance
VAR_SAMP and VAR_POP
Given a set of integer, decimal, or floating-point numbers, return the sample variance or population variance. The VAR_SAMP result is equivalent to the squared sample standard deviation of the same set of numbers. VAR_SAMP and VARIANCE are synonyms.
VAR_SAMP | VARIANCE (expression)
VAR_POP (expression)
The return type is either DOUBLE PRECISION (for floating-point inputs) or DECIMAL (for all other inputs).
For example:
premdb=# select avg(avg_att), var_samp(avg_att) varsamp, var_pop(avg_att) varpop
from team where avg_att>0;
avg | varsamp | varpop
--------+------------+------------
36.461 | 227.433898 | 216.062203
(1 row)
In this example, the variance results are rounded:
premdb=# select avg(avg_att), round(var_samp(avg_att)) varsamp, round(var_pop(avg_att)) varpop
from team where avg_att>0;
avg | varsamp | varpop
--------+---------+--------
36.461 | 227 | 216
(1 row)
Note: The VARIANCE or VAR_SAMP function for an expression that consists of a single value returns NULL
. The VAR_POP function for an expression that consists of a single value returns 0
).