Re: Array manipulation/syntax question - Mailing list pgsql-general

From Ron Mayer
Subject Re: Array manipulation/syntax question
Date
Msg-id 4280789E.1020905@cheapcomplexdevices.com
Whole thread Raw
In response to Array manipulation/syntax question  (Bart Grantham <bart@logicworks.net>)
List pgsql-general
Bart Grantham wrote:
> Hello again.  I had a problem a few weeks ago with using IN ( some_array
> ) having really rough performance.  Special thanks to Ron Mayer for the
> suggestion of using int_array_enum(some_array) to join against.  I had
> to upgrade to PG8 but that technique works really well.  Now I have a
> question about array manipulation.  Specifically, how can I build an
> array from the result of a query without resorting to array_append()?

Well, the same contrib module with int_array_enum() also has
aggregate called int_array_aggregate that turns a column into an array.

> -- my_array is an INT[]
>
> _my_array := select some_column from some_table;

so this:
  SELECT int_array_aggregate(some_column) from some_table;
might be what you want.

> ... in plpgsql?

Well... the function from the contrib module was in C, so I guess
it doesn't strictly meet what you asked, but it works very well
for me. ;-)

    Ron Mayer

PS: the stuff in /contrib/intarray may be useful too, for
     indexing, merging, and many other tricks on the integer arrays.

pgsql-general by date:

Previous
From: Julian Legeny
Date:
Subject: Re: ORDER BY options (how to order data as AAA, aaa, BBB, bbb, ... ZZZ, zzz)
Next
From: joffer
Date:
Subject: unsuscribe