Re: Problem with custom aggregates and record pseudo-type - Mailing list pgsql-general

From Tom Lane
Subject Re: Problem with custom aggregates and record pseudo-type
Date
Msg-id 363.1322756378@sss.pgh.pa.us
Whole thread Raw
In response to Problem with custom aggregates and record pseudo-type  (Maxim Boguk <maxim.boguk@gmail.com>)
Responses Re: Problem with custom aggregates and record pseudo-type  (Maxim Boguk <maxim.boguk@gmail.com>)
List pgsql-general
Maxim Boguk <maxim.boguk@gmail.com> writes:
> I created special custom aggregate function to append arrays defined as:
> CREATE AGGREGATE array_accum (anyarray)
> (
>     sfunc = array_cat,
>     stype = anyarray,
>     initcond = '{}'
> );


> On arrays of common types it work without any problems:
> SELECT array_accum(i) from (values (ARRAY[1,2]), (ARRAY[3,4])) as t(i);
>  array_accum
> -------------
>  {1,2,3,4}
> (1 row)


> However once I try use it with record[] type I get an error:
> SELECT array_accum(i) from (values (ARRAY[row(1,2),row(2,3)]),
> (ARRAY[row(1,2),row(2,3)])) as t(i);
> ERROR:  cannot concatenate incompatible arrays

Hm ... it looks like this case can be made to work with a simple adjustment
to getTypeIOData, but in the meantime you might be able to get away with
leaving the initial value as NULL (ie, leave off the initcond clause).
The only behavioral difference would be that you'd get NULL not an empty
array for zero rows of input.

            regards, tom lane

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: session hang for same row update
Next
From: Red Light
Date:
Subject: recursive inner trigger call