CREATE FUNCTION ssq_init (dummy float)
RETURNING float;
RETURN 0;
END FUNCTION;
CREATE FUNCTION ssq_iter (result float, value float)
RETURNING float;
RETURN result + value * value;
END FUNCTION;
CREATE FUNCTION ssq_combine(partial1 float, partial2 float)
RETURNING float;
RETURN partial1 + partial2;
END FUNCTION;
CREATE FUNCTION ssq_final(final float)
RETURNING float;
RETURN final;
END FUNCTION;
CREATE AGGREGATE sumsq WITH
(INIT = ssq_init,
ITER = ssq_iter,
COMBINE = ssq_combine,
FINAL = ssq_final);
SELECT SUMSQ(b) FROM c_test;