aggregate returning anyarray and 'cannot determine result data type'

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема aggregate returning anyarray and 'cannot determine result data type'
Дата
Msg-id 5356EC2E.3090900@fuzzy.cz
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Craig Libscomb
Дата:
Сообщение: Re: Can't delete role because of unknown object
Следующее
От: Wells Oliver
Дата:
Сообщение: Using 9.3 as a slave to 9.1 for upgrade purposes