Skip to content

Count distinct not supported? #169

@rhcarvalho

Description

@rhcarvalho

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions