Re: Function array_agg(array)

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Ali Akbar <the(dot)apaan(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Function array_agg(array)
Date: 2014-10-22 13:51:33
Message-ID: CAFj8pRApxKMi0zDg+q6TcE+4ZQQ8uE8tgydkS3jYGLTQ1_JKXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

2014-10-19 8:02 GMT+02:00 Ali Akbar <the(dot)apaan(at)gmail(dot)com>:

> So, is there any idea how we will handle NULL and empty array in
>> array_agg(anyarray)?
>> I propose we just reject those input because the output will make no
>> sense:
>> - array_agg(NULL::int[]) --> the result will be indistinguished from
>> array_agg of NULL ints.
>> - array_agg('{}'::int[]) --> how we determine the dimension of the
>> result? is it 0? Or the result will be just an empty array {} ?
>>
>
> This updated patch rejects NULL and {} arrays as noted above.
>
>

I agree with your proposal. I have a few comments to design:

1. patch doesn't hold documentation and regress tests, please append it.

2. this functionality (multidimensional aggregation) can be interesting
more times, so maybe some interface like array builder should be preferred.

3. array_agg was consistent with array(subselect), so it should be fixed too

postgres=# select array_agg(a) from test;
array_agg
-----------------------
{{1,2,3,4},{1,2,3,4}}
(1 row)

postgres=# select array(select a from test);
ERROR: could not find array type for data type integer[]

4. why you use a magic constant (64) there?

+ astate->abytes = 64 * (ndatabytes == 0 ? 1 : ndatabytes);
+ astate->aitems = 64 * nitems;

+ astate->nullbitmap = (bits8 *)
+ repalloc(astate->nullbitmap, (astate->aitems + 7) / 8);

Regards

Pavel

> Regards,
> --
> Ali Akbar
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-10-22 14:13:58 Re: Reducing lock strength of adding foreign keys
Previous Message Simon Riggs 2014-10-22 13:47:16 Re: pg_receivexlog --status-interval add fsync feedback