不能在match子句之外使用^ xxx

Ram*_*ano 25 elixir ecto phoenix-framework

这个功能:

defp entries(query, page_number, page_size) do
  offset = page_size * (page_number - 1)

  query
  |> limit([_], ^page_size) # error
  |> offset([_], ^offset)
  |> Repo.all
end
Run Code Online (Sandbox Code Playgroud)

给出了一个例外:

cannot use ^pg_size outside of match clauses
Run Code Online (Sandbox Code Playgroud)

为什么这样以及如何解决?

mic*_*ala 71

这通常表示您没有从中导入适当的宏Ecto.Query.