数値変換を回避するためにこれを行う方法があるかもしれませんが、これで仕事が完了するはずです:
SELECT
key, Sum(to_number(value, '999999999999')) FROM (
SELECT (each(goals)).key, (each(goals)).value FROM public.statistics
) as s
Group By
key
http://sqlfiddle.com/#!1/eb745/10/0
これは、Postgres がこのように曲げたくない大きな臭いですが、次のようになります。
create table test (id int, goals hstore);
Insert Into Test(id, goals) Values (30059, '3=>123');
Insert Into Test(id, goals) Values (27333, '3=>200,5=>10');
Create Function hagg() returns hstore As
'Declare ret hstore := ('''' :: hstore); i hstore; c cursor for Select hstore(key, (x.Value::varchar)) From (Select key, Sum((s.value::int)) as Value From (Select (each(goals)).* From Test) as s Group By key) as x; BEGIN Open c; Loop Fetch c into i; Exit When Not FOUND; ret := i || ret; END LOOP; return ret; END' Language 'plpgsql';
SQL フィドルで複数行の関数本体を受け入れることができませんでした。実際の postgres では、これを $$ で引用して少し分割できるはずです。
http://sqlfiddle.com/#!1/e2ea7/1/0