PostgreSQL var_pop() Function
The PostgreSQL var_pop()
function is an aggregate function that computes the population variance (square of the population standard deviation) for all non-null input values.
var_pop()
Syntax
Here is the syntax of the PostgreSQL var_pop()
function:
var_pop(expr)
Typically, we use the var_pop()
function like:
SELECT var_pop(expr), ...
FROM table_name
[WHERE ...]
[GROUP BY group_expr1, group_expr2, ...];
Parameters
expr
-
Required. A column name or expression.
Return value
The PostgreSQL var_pop()
function returns the population variance (square of the population standard deviation) for all non-null input values.
Note that the var_pop()
function only handles non-null values. That is, null values are ignored by the var_pop()
function.
var_pop()
Examples
To demonstrate usages of the PostgreSQL var_pop()
function, we simulate a temporary table using the following statement with UNION
and SELECT
:
SELECT 4 x
UNION
SELECT 5 x
UNION
SELECT 6 x;
x
---
4
6
5
(3 rows)
The following statement uses the var_pop()
function to calculate the population variance of all the values in the x
column:
SELECT var_pop(x)
FROM (
SELECT 4 x
UNION
SELECT 5 x
UNION
SELECT 6 x
) t;
var_pop
------------------------
0.66666666666666666667
(1 rows)