Search Postgresql Archives

User-defined function with anyrange[]

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

 



Hello,

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:

ERROR:  type anyrange[] does not exist

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;

    paul=# select range_agg4(daterange('2016-05-04', '2016-07-01'));
    ERROR:  invalid input syntax for type date: "[2016-05-04,2016-07-01)"
    CONTEXT:  PL/pgSQL function range_agg4(anyrange) while casting
return value to function's return type

So I guess it thinks that daterange in means date[] out (not daterange[] out).

The best I can think of is to define range_agg(anyelement) that
returns anyarray. That actually works how I hope:

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

    paul=# select range_agg3(daterange('2016-05-04', '2016-07-01'));
             range_agg3
    -----------------------------
     {"[2016-05-04,2016-07-01)"}

But of course that is not as restricted as I'd like. Are there any
better options?

Thanks,
Paul




[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