Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24627

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?

Upvotes: 2

Views: 1174

Answers (2)

justapilgrim
justapilgrim

Reputation: 6882

The geo library has moved all Ecto-related code to a separate library (see related pull request here).

To use the Ecto.Type implementation of PostgreSQL point datatype, use the geo_postgis library.

Upvotes: 1

Dogbert
Dogbert

Reputation: 222358

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

Upvotes: 3

Related Questions