Question about the behaviour of unsafe_validate_unique/4

So, I have a validation that should tell my frontend ( even “unsafely” ) that a value already is registered into the database. Then I made this:

  def validate_changeset(tribe = %Tribe{}, attrs) do
    changeset(tribe, attrs)
    |> validate_required(:name, message: gettext("Mandatory field"))
    # |> unique_constraint(:name, message: gettext("Tribe already exists"))
    |> unsafe_validate_unique(:name,
        Repo,
        message: gettext("Tribe already exists"),
        query: from(t in Tribe, where: ilike(t.name, ^"%#{attrs.name}%"))
      )
    |> Map.put(:action, :validate)
  end

But, the query, which is shown in debug mode reads:

SELECT TRUE FROM "tribes" AS t0 WHERE (t0."name" ILIKE $1) AND (t0."name" = $2) LIMIT 1 ["%ALKE%", "ALKE"]

Well, maybe I’m misunderstanding how this validation works, but I was expecting that only the query I have on the fourth argument would be made. Like so:

SELECT TRUE FROM "tribes" AS t0 WHERE (t0."name" ILIKE $1) LIMIT 1 ["%ALKE%"]

Is that so ? Why the resulting query concatenates another query even though I specified one there ? Where in the docs can I get a reference about this behaviour and, if is possible, how can I overwrite/prevent the aditional query of running ?

The query option allows you to customize the set of queried data, but not the uniqueness conditional. You’ll want to create a custom valitation given you’re not checking for uniqueness, but for similarity.

I see where I was doing wrong… I’ll create a custom validation to be used in my app, then

Thank you!