Re: Array manipulation/syntax question

From: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>
To: Bart Grantham <bart(at)logicworks(dot)net>
Subject: Re: Array manipulation/syntax question
Date: 2005-05-10 09:02:22
Message-ID: 4280789E.1020905@cheapcomplexdevices.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2005-05-10 09:37:50 alter views
Previous Message Vidya 2005-05-10 08:38:12 Re: function call error