Pairwise array sum aggregate function?

Поиск
Список
Период
Сортировка
От François Beausoleil
Тема Pairwise array sum aggregate function?
Дата
Msg-id BFABC9D5-D791-428E-95B9-8DB690E74711@teksol.info
обсуждение исходный текст
Ответы Re: Pairwise array sum aggregate function?  (David G Johnston <david.g.johnston@gmail.com>)
Re: Pairwise array sum aggregate function?  (Joe Conway <mail@joeconway.com>)
Список pgsql-general
Hi all,

NOTE: Also posted to StackOverflow: http://stackoverflow.com/questions/24997131/pairwise-array-sum-aggregate-function

I have a table with arrays as one column, and I want to sum the array elements together:

> create table regres(a int[] not null);
> insert into regres values ('{1,2,3}'), ('{9, 12, 13}');
> select * from regres;
     a
-----------
 {1,2,3}
 {9,12,13}

I want the result to be:

{10, 14, 16}

that is: {1 + 9, 2 + 12, 3 + 13}.

Does such a function already exist somewhere? The intagg extension looked like a good candidate, but such a function
doesnot already exist. 

The arrays are expected to be between 24 and 31 elements in length, all elements are NOT NULL, and the arrays
themselveswill also always be NOT NULL. All elements are basic int. There will be more than two rows per aggregate. 

My implementation target is:

 PostgreSQL 9.1.13 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit

Thanks!
François



В списке pgsql-general по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: hstore/jsonb support in hibernate/JPA
Следующее
От: Kevin Grittner
Дата:
Сообщение: Re: Checkpoint_segments optimal value