About this question
I have a cost column in my postgres db whose type is varchar. It stores the costs of each service a client gets in this format "KES 0.80". I am trying to sum up everything to get a cost breakdown.
This is how my query looks
select sum(cast(split_part("cost", ' ', 2) as double precision)) from send_log;
I am having a challenge casting the string to double precision so that I can get the sum. This is the error i am getting
ERROR: invalid input syntax for type double precision: ""
And if i try to cast into an integer i get this error
ERROR: invalid input syntax for integer: "0.8000"
I am looking for a better method to cast the string to double precision or advise on how I can format my query to get the total sum from the cost column. Any pointers or useful links will be appreciated.