title: Should I use require or import while using Ecto?
body: <p>I'm relatively new to the language, and have already read the <a href="https://elixir-lang.org/getting-started/alias-require-and-import.html" rel="nofollow noreferrer">differences</a> between the <code>require</code> and <code>import</code> keywords. Nevertheless I can't seem to understand the following behavior while using Ecto.</p>
  <p>So, I want to extract a <code>fragment</code> that's commonly used to get a value from a json field. Reading the Ecto <a href="https://hexdocs.pm/ecto/Ecto.Query.html#dynamic/2" rel="nofollow noreferrer">docs</a> I understand that in order to extract a <code>fragment</code> I have to wrap it on a <code>dynamic</code> macro. So I'm trying to implement it like this:</p>
  <pre><code>defmodule Foo do
    require Ecto.Query
  
    ...
  
    defp foo_fragment() do
      dynamic([t], fragment(&quot;?.json-&gt;&gt;'foo'&quot;, t))
    end
  end
  </code></pre>
  <p>To which I get the following warning</p>
  <pre><code>variable &quot;t&quot; does not exist and is being expanded to &quot;t()&quot;, please use parentheses to remove the ambiguity or change the variable name
  </code></pre>
  <p>Which seems reasonable enough, but isn't mentioned on the Ecto documentation. Looking for answers I found this SO <a href="https://stackoverflow.com/questions/46741389/variable-does-not-exist-when-im-try-to-make-a-query-with-ecto">question</a> where is recommended to use <code>import Ecto.Query</code>. I also noticed that it's used that way on the Ecto docs examples (probably for aesthetic reasons though).</p>
  <p>To my surprise upon trying it, the warning on the previous code it's gone.</p>
  <p>Is there something I'm missing regarding these keywords? I thought both were equivalent regarding the usage of macros, <code>require</code> being a more conservative approach as to keeping namespaces apart. Thanks!</p>