Search Postgresql Archives

Re: User-defined function with anyrange[]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul A Jungwirth <pj@xxxxxxxxxxxxxxxxxxxxxxxx> writes:
> I want to make an aggregate function range_agg(anyrange) that returns
> anyrange[]. But when I try to define it, Postgres tells me it doesn't
> know what an anyrange[] is. I get this error:

Yeah, there is no such thing as anyrange[], nor arrays over any other
pseudo-type either.

> I also tried taking an anyrange and returning an anyarray, which does
> let me define the function, but upon calling it I get an error. For
> example:

>     paul=# CREATE OR REPLACE FUNCTION range_agg4(anyrange)
>     RETURNS anyarray
>     AS $$
>     BEGIN
>       RETURN ARRAY[$1];
>     END;
>     $$
>     LANGUAGE plpgsql;

The trouble with this is that anyarray and anyrange are both implicitly
related to the "anyelement" pseudo-type, which represents their element
type.  So if anyrange is associated with daterange in a particular
function call, then anyelement is associated with date, and then anyarray
is associated with date[] not daterange[].

I don't think there's any way to get what you want using a single
polymorphic function, at least not without some sort of extension to
the polymorphism rules.  However, you can use overloading to define
several functions of the same name, and just write out one for each
range type you actually need this functionality for.  I haven't really
seen applications that need so many range types that this'd be
intolerable.

			regards, tom lane




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux