Problem with custom aggregates and record pseudo-type

From: Maxim Boguk <maxim(dot)boguk(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem with custom aggregates and record pseudo-type
Date: 2011-12-01 05:46:56
Message-ID: CAK-MWwTyJqJdPoYeCpO3RZFFfeBh0aiiFbxCToW-gbiFgSwGtg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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
DETAIL: Arrays with element types record[] and record are not compatible
for concatenation.

The base function of the aggregate:
array_cat work with record[] without any complains:
SELECT array_cat(ARRAY[row(1,2),row(2,3)], ARRAY[row(1,2),row(2,3)]);
array_cat
-----------------------------------
{"(1,2)","(2,3)","(1,2)","(2,3)"}

What I doing wrong? Or how to create correct version of such aggregate
function?

--
Maxim Boguk
Senior Postgresql DBA.

Phone RU: +7 910 405 4718
Phone AU: +61 45 218 5678

Skype: maxim.boguk
Jabber: maxim(dot)boguk(at)gmail(dot)com

LinkedIn profile: http://nz.linkedin.com/in/maximboguk
If they can send one man to the moon... why can't they send them all?

МойКруг: http://mboguk.moikrug.ru/
Сила солому ломит, но не все в нашей жизни - солома, да и сила далеко не
все.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Venkat Balaji 2011-12-01 05:59:57 Re: How to restore the table space tar files created by pg_basebackup?
Previous Message Tom Lane 2011-12-01 00:49:46 Re: Using a domain