elixir-sqlite/ecto_sqlite3

Count distinct not supported?

Closed this issue · 2 comments

I'm getting an error "Distinct not supported in expressions", coming from:

defp expr({fun, _, args}, sources, query) when is_atom(fun) and is_list(args) do
{modifier, args} =
case args do
[_rest, :distinct] ->
raise Ecto.QueryError,
query: query,
message: "Distinct not supported in expressions"
_ ->
{[], args}
end

My query is like:

    from(
      s in SomeSchema,
      where: s.tenancy_id == ^tenancy_id,
      select: %{
        users_count: count(s.user_id, :distinct)
      }
    )
    |> App.Repo.one()

Is there a supported way to write the query other than using a fragment?

I'll need to check. I remember not implementing this for a reason, but I can not recall why I did not implement it. There was a limitation with how ecto composed a query for this. I'll need to investigate again.

This was solved in #171 (thanks @aseigo) and released in v0.20.0 (thanks @warmwaffles).