SELECT (jsonb_array_elements((balance)::jsonb->'savings')->'amount')::float as virtual_balance FROM accounts WHERE id = 58117;
Result:
virtual_balance
---------------
162.09
0.16
I need to select this result to be added together, resulting in 162.25
the expected result should look like
virtual_balance
---------------
162,25
I needed it to be in the same select without using WHEN or other loops, my database and postgres
virtual_balance
---------------
162,25
2
Answers
Put the set-returning function in a lateral table expression, then you can use
SUM
:or
You can add the decimal separator as a comma, change it to characters (if you need the numeric values you have to convert it back to float later) using to_char:
https://www.postgresql.org/docs/current/functions-formatting.html
Query:
The reason for using it like this is because of the following:
So D is the comma instead of period (.),
Tested on PosgreSQL 16