aggregate
CORR
Computes Pearson linear correlation for complete numeric pairs. Constant inputs or insufficient variation yield NULL; correlation does not establish causation. Example target: PostgreSQL 17; inline synthetic data; no extensions.
Formal Syntax & Structure
sql syntaxsql
CORR(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 corr(y,x) FROM sample;