Skip to content

Distinct with 2 keys or more #4671

@abdelhalim97

Description

@abdelhalim97

Elixir version

1.18.3

Database and Version

MySql 8.0.35

Ecto Versions

ecto 3.12.5

Database Adapter and Versions (postgrex, myxql, etc)

ecto_sql 3.12

Current behavior

schema "logs" do
    field :action, :string
    field :user_id, :integer
    field :smth, :string
  end
from(l in Logs,
  distinct: [l.action, l.user_id]
)
|> Repo.all()

It returns a misleading error that confused me it says:

DISTINCT with multiple columns is not supported by MySQL in query:

from p0 in Ovice.Model.Log,
  distinct: [asc: p0.action, asc: p0.user_id],
  select: p0

I really thought that ecto doesnt support DISTINCT with more than single column when mysql does

Expected behavior

Expected that this query will do distinct on both fields like this examle that works fine and as expected:

 from(l in Logs,
select: [l.action, l.user_id],
      distinct: true
    )
    |> Repo.all()

Unless i misunderstood something, both queries should have same output.
If yes i d like to work on it myself please 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions