Search code examples
elixirphoenix-frameworkecto

cannot use ^xxx outside of match clauses


This function:

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

  query
  |> limit([_], ^page_size) # error
  |> offset([_], ^offset)
  |> Repo.all
end

gives an exception:

cannot use ^pg_size outside of match clauses

Why is that and how to fix it?


Solution

  • This is most usually a sign that you haven't imported appropriate macros from Ecto.Query.