From bdfa049ccb2bf96e1b3e50034879c18173e32b40 Mon Sep 17 00:00:00 2001 From: abdelhalim97 Date: Thu, 23 Oct 2025 00:11:49 +0100 Subject: [PATCH 1/2] enhance distinct error --- lib/ecto/adapters/myxql/connection.ex | 2 +- test/ecto/adapters/myxql_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ecto/adapters/myxql/connection.ex b/lib/ecto/adapters/myxql/connection.ex index f5a36695..bb30f76b 100644 --- a/lib/ecto/adapters/myxql/connection.ex +++ b/lib/ecto/adapters/myxql/connection.ex @@ -347,7 +347,7 @@ if Code.ensure_loaded?(MyXQL) do defp distinct(%ByExpr{expr: false}, _sources, _query), do: [] defp distinct(%ByExpr{expr: exprs}, _sources, query) when is_list(exprs) do - error!(query, "DISTINCT with multiple columns is not supported by MySQL") + error!(query, "To apply DISTINCT to multiple columns at once, use distinct: true") end defp select([], _sources, _query), diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index 43576b7c..726070a0 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -385,7 +385,7 @@ defmodule Ecto.Adapters.MyXQLTest do assert all(query) == ~s{SELECT s0.`x`, s0.`y` FROM `schema` AS s0} assert_raise Ecto.QueryError, - ~r"DISTINCT with multiple columns is not supported by MySQL", + ~r"To apply DISTINCT to multiple columns at once, use distinct: true", fn -> query = Schema |> distinct([r], [r.x, r.y]) |> select([r], {r.x, r.y}) |> plan() @@ -394,7 +394,7 @@ defmodule Ecto.Adapters.MyXQLTest do end assert_raise Ecto.QueryError, - ~r"DISTINCT with multiple columns is not supported by MySQL", + ~r"To apply DISTINCT to multiple columns at once, use distinct: true", fn -> query = from(row in Schema, as: :r, select: row.x) From 4c757305b394f0d90618559cc790095880c98995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 23 Oct 2025 21:07:48 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- lib/ecto/adapters/myxql/connection.ex | 2 +- test/ecto/adapters/myxql_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ecto/adapters/myxql/connection.ex b/lib/ecto/adapters/myxql/connection.ex index bb30f76b..aa7f4199 100644 --- a/lib/ecto/adapters/myxql/connection.ex +++ b/lib/ecto/adapters/myxql/connection.ex @@ -347,7 +347,7 @@ if Code.ensure_loaded?(MyXQL) do defp distinct(%ByExpr{expr: false}, _sources, _query), do: [] defp distinct(%ByExpr{expr: exprs}, _sources, query) when is_list(exprs) do - error!(query, "To apply DISTINCT to multiple columns at once, use distinct: true") + error!(query, "to apply DISTINCT to multiple columns in MySQL, use distinct: true") end defp select([], _sources, _query), diff --git a/test/ecto/adapters/myxql_test.exs b/test/ecto/adapters/myxql_test.exs index 726070a0..e33bff6a 100644 --- a/test/ecto/adapters/myxql_test.exs +++ b/test/ecto/adapters/myxql_test.exs @@ -385,7 +385,7 @@ defmodule Ecto.Adapters.MyXQLTest do assert all(query) == ~s{SELECT s0.`x`, s0.`y` FROM `schema` AS s0} assert_raise Ecto.QueryError, - ~r"To apply DISTINCT to multiple columns at once, use distinct: true", + ~r"to apply DISTINCT to multiple columns in MySQL, use distinct: true", fn -> query = Schema |> distinct([r], [r.x, r.y]) |> select([r], {r.x, r.y}) |> plan() @@ -394,7 +394,7 @@ defmodule Ecto.Adapters.MyXQLTest do end assert_raise Ecto.QueryError, - ~r"To apply DISTINCT to multiple columns at once, use distinct: true", + ~r"to apply DISTINCT to multiple columns in MySQL, use distinct: true", fn -> query = from(row in Schema, as: :r, select: row.x)