Function Reference

STDDEV_SAMP

Returns the sample standard deviation of the expression values in a group of rows.

PostgreSQL 17.5
STDDEV_SAMP(expression)

Parameters

expressionnumeric | double precision
Numeric expression

Return value

A number: numeric for integers and numeric, double precision for floating-point numbers; NULLs are ignored; NULL if there are fewer than two values

Examples

Sample and population deviation

PostgreSQL 17.5
SELECT STDDEV_SAMP(x) AS sample_stddev,
	STDDEV_POP(x) AS population_stddev
FROM (
		VALUES (2),
			(4),
			(4),
			(4),
			(5),
			(5),
			(7),
			(9)
	) AS t(x);
sample_stddevpopulation_stddev
2.13808993529939512.0000000000000000

Average price and its spread

PostgreSQL 17.5
SELECT family_member,
	ROUND(AVG(unit_price), 1) AS avg_price,
	ROUND(STDDEV_SAMP(unit_price), 1) AS price_stddev
FROM Payments
GROUP BY family_member
ORDER BY family_member;
family_memberavg_priceprice_stddev
11542.53485.8
210575.424521.6
3505.8948.3
4250.0141.4
5179.398.1

Details

It is the square root of VAR_SAMP. STDDEV is a synonym for STDDEV_SAMP, and STDDEV_POP computes the population deviation: it divides by n, not by n − 1.

See also