| From: | Ali Akbar <the(dot)apaan(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Function array_agg(array) |
| Date: | 2014-10-12 12:37:13 |
| Message-ID: | CACQjQLqX2v895YVMYABCXgVP4QLenXgqiRgx9v_5oz7t79G-0w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
2014-10-11 22:28 GMT+07:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Seems dangerous as heck; certainly it would have side-effects far more
> wide-ranging than just making this particular function work.
>
> A safer answer is to split array_agg into two functions,
> array_agg(anynonarray) -> anyarray
> array_agg(anyarray) -> anyarray
>
> I rather imagine you should do that anyway, because I really doubt
> that this hack is operating quite as intended. I suspect you are
> producing arrays containing arrays as elements, not true 2-D arrays.
> That's not a direction we want to go in I think; certainly there are
> no other operations that produce such things.
>
Thanks for the review. Yes, it looks like the patch produced array as the
elements. So, all array operations behaves wierdly.
In this quick & dirty patch, I am trying to implement the
array_agg(anyarray), introducing two new functions:
- array_agg_anyarray_transfn
- array_agg_anyarray_finalfn
At first, i want to use accumArrayResult and makeMdArrayResult, but it's
complicated to work with multi-dimensional arrays with those two functions.
So i combined array_cat with those function.
Currently, it cannot handle NULL arrays:
backend> select array_agg(a) from (values(null::int[])) a(a);
1: array_agg (typeid = 1007, len = -1, typmod = -1, byval = f)
----
ERROR: cannot aggregate null arrays
Regards,
--
Ali Akbar
| Attachment | Content-Type | Size |
|---|---|---|
| array_agg_anyarray-2.patch | text/x-diff | 12.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Marko Tiikkaja | 2014-10-12 12:40:35 | Re: UPSERT wiki page, and SQL MERGE syntax |
| Previous Message | Matthew Woodcraft | 2014-10-12 12:36:51 | Re: UPSERT wiki page, and SQL MERGE syntax |