Re: Array aggregation. Was: PostgreSQL Final Release ... Monday? - Mailing list pgsql-hackers

From mlw
Subject Re: Array aggregation. Was: PostgreSQL Final Release ... Monday?
Date
Msg-id 3C5886D9.ECEE93C0@mohawksoft.com
Whole thread Raw
In response to PostgreSQL Final Release ... Monday?  ("Marc G. Fournier" <scrappy@hub.org>)
List pgsql-hackers
It is used as an aggregation function. It only works on integers, and assumes
sizeof(int) == sizeof(void *)

There are two functions:

int_array_aggregate(int4)
and 
int_array_enum(int4[])


One creates an integer array as:

create table tst as select some_field, int_array_aggregate(int_field) as field
from table group by some_field;

This will poduce one row for all the unique "some_fields" with an array of all
"int_field" associated.

To extract this, you use int_array_enum(int_array); whic returns multiple
results.





Hannu Krosing wrote:
> 
> On Thu, 2002-01-31 at 02:36, mlw wrote:
> >
> > I submitted a "contrib" project for integer array
> > aggregation/enumeration. I didn't see it in rc2.
> >
> 
> Some general questions about arrays  -
> 
> 1. Could this aggregation/enumeration be done in a generic way, so
>    that you could aggregate over any array ?
> 
>    The only generic function I currently know of is count(), but it
>    is generic only on argument side, i.e count(any) returns always
>    integer.
> 
> 2. Is there a way to define a function such that
> 
>   declare make_array(any) returns any[] ?
> 
> 3. Also, can I prescribe order of aggregation (aggregation applied
>    _after_ ORDER BY) that would act in a way similar to HAVING .
> 
> 4. what arguments must I give to array_in so that it produces an
>    array of specific kind ? I tried some more obvious things and
>    really got nowhere.
> 
> --------------
> Hannu
> 
> PS. I attach an alpha-contrib ofPL/PgSQL code to compare intarrays.
> I have not had time to tie these ops to indexes
> 
> --------------
> Hannu
> 
>   -------------------------------------------------------------------------------
>                      Name: ARRAY_COMP.SQL
>    ARRAY_COMP.SQL    Type: text/x-sql
>                  Encoding: quoted-printable


pgsql-hackers by date:

Previous
From: Bill Studenmund
Date:
Subject: Re: RFD: schemas and different kinds of Postgres objects
Next
From: Hiroshi Inoue
Date:
Subject: Re: RFD: schemas and different kinds of Postgres objects