Skip to content

Instantly share code, notes, and snippets.

@bryanjos
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjos/f2b44b5ca08c82169bd2 to your computer and use it in GitHub Desktop.
Save bryanjos/f2b44b5ca08c82169bd2 to your computer and use it in GitHub Desktop.
postgis function macros
defmodule Geo.PostGIS.Functions do
def st_area(geom) do
quote do: fragment("ST_Area(?)", unquote(geom))
end
#Example query
query = from location in Location, limit: 5, select: st_area(location.geom)
results = Repo.all(query)
end
** (Ecto.Query.CompileError) `st_area(location.geom())` is not a valid query expression.
* If you intended to call a database function, please check the documentation
for Ecto.Query to see the supported database expressions
* If you intended to call an Elixir function or introduce a value,
you need to explicitly interpolate it with ^
(ecto) expanding macro: Ecto.Query.select/3
test/geo/ecto_test.exs:55: Geo.Ecto.Test."test postgis functions"/1
(ecto) expanding macro: Ecto.Query.from/2
test/geo/ecto_test.exs:55: Geo.Ecto.Test."test postgis functions"/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment