Ecto sum() distinct support

As per http://www.postgresqltutorial.com/postgresql-sum-function/

Postgres support SUM(DISTINCT column)

Is there any way to do this in Ecto’s sum function?

Something like sum(payment.total, :distinct)

Ecto’s count currently supports this.

  defmacro sum_dist(column) do
    quote do
      fragment("SUM(DISTINCT ?)", unquote(column))
    end
  end
3 Likes