I am trying to run these lines:
create type _stats_agg_result_type AS (
count bigint,
min double precision,
max double precision,
mean double precision,
variance double precision,
skewness double precision,
kurtosis double precision
);
create or replace function _stats_agg_finalizer(_stats_agg_accum_type)
returns _stats_agg_result_type AS '
BEGIN
RETURN row(
$1.n,
$1.min,
$1.max,
$1.m1,
$1.m2 / nullif(($1.n - 1.0), 0),
case when $1.m2 = 0 then null else sqrt($1.n) * $1.m3 / nullif(($1.m2 ^ 1.5), 0) end,
case when $1.m2 = 0 then null else $1.n * $1.m4 / nullif(($1.m2 * $1.m2) - 3.0, 0) end
);
END;
'
language plpgsql;
Unfortunately I get following error (w.r.t. the _stats_agg_finalizer function):
RETURN must specify a record or row variable in function returning row
Version I'm running:
PostgreSQL 9.2.24 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
I am new to PostgreSQL and I have not been able to fix this error. Appreciate any help, thanks!
ROW()expression to_stats_agg_result_typeor declaring arecordvariable, assigning to it and returning that?