Defining functions for arrays of any number type

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Defining functions for arrays of any number type
Date: 2014-12-11 04:21:39
Message-ID: CA+6hpamvP3eOkg5HooqKuBe+qiwF28puFt3FufMfeRmcBg4qnA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Melvin Davidson 2014-12-11 04:32:19 Re: Stored procedure workflow question
Previous Message Bruce Momjian 2014-12-11 03:38:37 Re: I did some testing of GIST/GIN vs BTree indexing…