Ecto: How to sum a field with Money datatype

I have a field %{total: #Money<:USD, 120.000>} with custom money type.
I am using Ecto’s QueryApi sum like this. sum(total)
But I’m getting ERROR 42883 (undefined_function) function sum(money_with_currency) does not exist
I tried using type(sum(total), :decimal) but also doesnt work.

If this is using ex_money you need to install the custom postgres function to sum up values of the composite type.

Yes the app is using ex_money, and which custom postgres function you are referring to?

In older versions this was part of ex_money directly, so be sure to check which version you‘re using.


This must be the solution, I’ll give it a try. Thank you very much!