Search code examples
postgresqlelixirecto

How to use point column type in Ecto using PostgreSQL


I can see that Postgrex lib supports postgreSQL's point type but I can't figure out how I can use it in model. I can specify point type for column in migration but when I specify it in the model like this:

schema "something" do
  field :position, :point
end

I get ** (ArgumentError) invalid or unknown type :point for field :position. Anything special I should do to make it work?


Solution

  • Ecto does not contain any Ecto.Type implementing module for the point data type in PostgreSQL. You can either define your own module with Ecto.Type behavior for it or use a library like geo which includes Geo.Point which implements the Ecto.Type behavior.

    With geo, your schema would look something like:

    schema "something" do
      field :position, Geo.Point
    end