PostgreSQL stddev_pop() Function

The PostgreSQL stddev_pop() function is an aggregate function that computes the population standard deviation of all non-null input values.

stddev_pop() Syntax

Here is the syntax of the PostgreSQL stddev_pop() function:

stddev_pop(expr)

Typically, we use the stddev_pop() function like:

SELECT stddev_pop(expr), ...
FROM table_name
[WHERE ...]
[GROUP BY group_expr1, group_expr2, ...];

Parameters

expr

Required. A column name or expression.

Return value

The PostgreSQL stddev_pop() function returns the population standard deviation of all non-null input values.

Note that the stddev_pop() function only handles non-null values. That is, null values ​​are ignored by the stddev_pop() function.

stddev_pop() Examples

To demonstrate usages of the PostgreSQL stddev_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 stddev_pop() function to calculate the population standard deviation of all the values ​​in the x column:

SELECT stddev_pop(x)
FROM (
    SELECT 4 x
    UNION
    SELECT 5 x
    UNION
    SELECT 6 x
  ) t;
       stddev_pop
------------------------
 0.81649658092772603273
(1 rows)