Re: User-defined function with anyrange[]

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: User-defined function with anyrange[]
Дата
Msg-id 69895.1530913898@sss.pgh.pa.us
обсуждение исходный текст
Ответ на User-defined function with anyrange[]  (Paul A Jungwirth <pj@illuminatedcomputing.com>)
Ответы Re: User-defined function with anyrange[]
Список pgsql-general
Paul A Jungwirth <pj@illuminatedcomputing.com> 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


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

Предыдущее
От: Duarte Carreira
Дата:
Сообщение: Re: correcting tablespaces inside data folder
Следующее
От: DiasCosta
Дата:
Сообщение: Re: Cloning schemas