Re: Parameters in user-defined aggregate final functions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Parameters in user-defined aggregate final functions
Дата
Msg-id 24133.1515712297@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Parameters in user-defined aggregate final functions  (Esteban Zimanyi <ezimanyi@ulb.ac.be>)
Ответы Re: Parameters in user-defined aggregate final functions
Список pgsql-hackers
Esteban Zimanyi <ezimanyi@ulb.ac.be> writes:
> How to tell PostgreSQL that my final function also needs a parameter? I am
> working on PostgreSQL 10.1. I know that according to the documentation
> direct parameters are only allowed for ordered-set aggregates, but I would
> also need a direct parameter for "normal" aggregates.

So define it as an ordered-set aggregate, and just ignore the question
of whether you need to sort the input (which is something that we leave
to the aggregate function to do anyway).  The syntax would be a little
weird/non-orthogonal, but you can blame the SQL committee for that.

regression=# create function trans(int, int) returns int language sql
regression-# as 'select $1+$2' strict;
CREATE FUNCTION
regression=# create function final(int, float8) returns float8 language sql
regression-# as 'select $1*$2' strict;
CREATE FUNCTION
regression=# create aggregate myosa(float8 order by int) (
regression(# sfunc = trans, stype = int, finalfunc = final);
CREATE AGGREGATE
regression=# select sum(ten), myosa(0.5) within group (order by ten) from tenk1;
  sum  | myosa
-------+-------
 45000 | 22500
(1 row)


            regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: David Fetter
Дата:
Сообщение: Re: Parameters in user-defined aggregate final functions
Следующее
От: Vaishnavi Prabakaran
Дата:
Сообщение: Re: [HACKERS] PATCH: Batch/pipelining support for libpq