I would use unnest
together with array_agg
, like this:
SQL Fiddle
PostgreSQL 9.3.1 Schema Setup:
create table t (
A double precision[5],
B double precision[5]);
insert into t values
('{3,2,0,3,1}', '{1,0,3,2,5}');
Query 1:
with c as(
select unnest(a) a, unnest(b) b from t)
select array_agg(a) a, array_agg(b) b, array_agg(a + b) c from c
Results:
| A | B | C |
|-----------|-----------|-----------|
| 3,2,0,3,1 | 1,0,3,2,5 | 4,2,3,5,6 |
As commented below, the query above will work well for the arrays of the same size. Otherwise it may produce an unexpected result.
If you need to support the arrays of different size, use this query:
with a as(
select unnest(a) a from t),
b as(
select unnest(b) b from t),
ar as(
select a, row_number() over() r from a),
br as(
select b, row_number() over() r from b),
c as(
select ar.a, br.b from ar inner join br on ar.r = br.r)
select array_agg(a) a, array_agg(b) b, array_agg(a + b) c from c;