Last active
August 29, 2015 14:17
-
-
Save bryanjos/f2b44b5ca08c82169bd2 to your computer and use it in GitHub Desktop.
postgis function macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** (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