Open Teslima02 opened 4 months ago
Just encountered this. You can use fragment/2
to get the sum:
total_amount: sum(fragment("(?).amount", field(transaction, :amount)))
This roughly translates to the following Postgres query:
select sum((transactions.amount).amount) from transactions;
What am trying to achieve
I want to be able to query total transaction with the
sum function
andmoney composite type
The problem I am using elixir money library and each time I ran the query I got the following error
I searched for the issue but solutions I found it not working for me, I checked similar issue on elixir forum.
https://elixirforum.com/t/ecto-how-to-sum-a-field-with-money-datatype/26736/4
Proposed solution but is not working