Defining functions for arrays of any number type

Поиск
Список
Период
Сортировка
От Paul Jungwirth
Тема Defining functions for arrays of any number type
Дата
Msg-id CA+6hpamvP3eOkg5HooqKuBe+qiwF28puFt3FufMfeRmcBg4qnA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Defining functions for arrays of any number type  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hello,

I'm working on a package of functions that compute statistics on
arrays of numbers. For example this one computes a histogram from a
bunch of values plus some bucket characteristics:

CREATE OR REPLACE FUNCTION
array_to_hist(double precision[], double precision, double precision, int)
RETURNS int[]
AS 'aggs_for_arrays', 'array_to_hist'
LANGUAGE c;

Now suppose I wanted this function to accept not just arrays of double
precision values, but arrays of any numeric type. I don't see any
pseudotype like that in this list:

http://www.postgresql.org/docs/9.3/static/datatype-pseudo.html

So how would you declare this function? Should I use anyarray for the
first parameter and anyelement for the next two (start of first bucket
and bucket width), and then just have the implementation complain if
the type isn't numeric? Or is there a better way than that?

Is it legal to define a bunch of functions all called `array_to_hist`
for the different numeric types, and have them all implemented by the
same C function?

Thanks,
Paul

--
_________________________________
Pulchritudo splendor veritatis.


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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: I did some testing of GIST/GIN vs BTree indexing…
Следующее
От: Melvin Davidson
Дата:
Сообщение: Re: Stored procedure workflow question