Usando Scipy com PlPython dentro do PostgreSQL
Nesse exemplo você precisa já ter o plpythonu3 instalado, com pip3 e scipy.
Nesse exemplo usamos a correlação de Pearson do Scipy
DO $$
import scipy from scipy
import stats
def getValue(v):
return v["unnest"]
# could also return the first key in the dict
# return list(v.values())[0]
x = plpy.execute("SELECT unnest('{1,2,3,4,5}'::INT[])")
y = plpy.execute("SELECT unnest('{1,2,3,4,5}'::INT[])")
x = list(map(getValue,x))
y = list(map(getValue,y))
plpy.notice(scipy.stats.pearsonr(x,y))
$$ LANGUAGE 'plpython3u';