Hi all,
I needed to implement an aggregate producing a random sample, with an
upper bound on the number of items. I.e. not the usual "5% of values"
but "up to 1000 values".
So my plan was to do something like this:
sample_append(internal, anyelement, int) -> internal
sample_final(internal) -> anyarray
CREATE AGGREGATE sample_agg(anyelement, int) (
SFUNC = sample_append,
STYPE = internal,
FINALFUNC = sample_final
);
where 'internal' represents a pointer to a structure with all the info
(limit, currently accumulated sample, ...).
However this leads to
ERROR: cannot determine result data type
DETAIL: A function returning a polymorphic type must have at least
one polymorphic argument
because 'sample_final' produces anyarray but has no polymorphic
argument. Sadly, the 'natural' solution of using anyarray instead of the
internal structure does not work because I have no way to pass the other
parameters to the final function (the last int in sfunc).
Any ideas how to solve this?
regards
Tomas