Add values from within a column with postgres

2

I'm trying to sum the values from within a column with postgres, the structure of the table is as follows:

id    |nome_municipio    |valores
1     |Porto Alegre      |100.01;95.0;50.1
2     |Ivoti             |87.0;80.1;45.1
3     |Novo Hamburgo     |210.0;99.2;100.0

I would like the final result to be

id    |nome_municipio    |valores   
1     |Porto Alegre      |245.2
2     |Ivoti             |207.2
3     |Novo Hamburgo     |409.2

Is this possible?

Postgres 9.1

    
asked by anonymous 29.01.2015 / 03:11

1 answer

3
select id , nome_municipio,  (SELECT SUM(s) FROM
UNNEST(CAST(regexp_split_to_array(valores, E';') as real[])) s)   from "tabela"
    
29.01.2015 / 05:37