aggregate
COVAR_SAMP
Measures joint variation using sample denominator N-1. Pairs containing NULL are omitted; fewer than two complete pairs give NULL. Example target: PostgreSQL 17; inline synthetic data; no extensions.
Formal Syntax & Structure
sql syntaxsql
COVAR_SAMP(y, x)Working Example
Example Snippetsql
WITH sample(id,x,y) AS (VALUES (1,1,2),(2,2,4),(3,3,6),(4,4,8),(5,NULL,4)) SELECT round(CAST(covar_samp(y,x) AS numeric),6) FROM sample;