Omit support functions
For completeness, the preceding examples show all four
support functions: INIT, ITER, COMBINE,
and FINAL. Because SUMSQ is a simple aggregate,
the examples could have omitted the INIT and FINAL functions.
You could use the following commands to create the SSQ2 aggregate:
CREATE FUNCTION ssq2_iter (result float, opr float)
RETURNING float;
IF result IS NULL THEN
LET result = (opr*opr);
ELSE
LET result = result + opr*opr;
END IF
RETURN result;
END FUNCTION;
CREATE FUNCTION ssq2_combine(partial1 float, partial2 float)
RETURNING float;
RETURN partial1 + partial2;
END FUNCTION;
CREATE AGGREGATE ssq2 WITH
(ITER = ssq2_iter,
COMBINE = ssq2_combine);