Skip to content

var_samp ​

Calculates the sample variance.

Variance describes the spread of the observations around their arithmetic mean. Its units are the square of the input units.

Syntax

text
var_samp(x)

Arguments

  • x — A numeric column or expression. NULL values are skipped.

Calculation

text
sum((x - mean) * (x - mean)) / (n - 1)

mean is the arithmetic mean of the non-NULL values, and n is their count. The sample calculation uses n - 1 because the observations estimate a larger population.

Returned value

An approximate REAL value. Fewer than two non-NULL inputs returns NULL. Nonfinite inputs return NULL; finite arithmetic overflow raises NUMERIC_OVERFLOW.

Examples

Measuring the spread of readings

sql
CREATE TABLE readings (value INTEGER);
INSERT INTO readings VALUES (1), (3), (5), (7), (9), (NULL);
sql
SELECT round(var_samp(value), 6) AS result
FROM readings
FORMAT csv;
text
10.0

A single observation

sql
CREATE TABLE single_reading (value INTEGER);
INSERT INTO single_reading VALUES (7), (NULL);
sql
SELECT var_samp(value)
FROM single_reading
FORMAT csv;
text
\N