aggregate returning anyarray and 'cannot determine result data type' - Mailing list pgsql-general

From Tomas Vondra
Subject aggregate returning anyarray and 'cannot determine result data type'
Date
Msg-id 5356EC2E.3090900@fuzzy.cz
Whole thread Raw
List pgsql-general
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


pgsql-general by date:

Previous
From: Craig Libscomb
Date:
Subject: Re: Can't delete role because of unknown object
Next
From: Wells Oliver
Date:
Subject: Using 9.3 as a slave to 9.1 for upgrade purposes