Rails: Converting from MySQL to PostGres interrupts Geokit Distance Calculations?

I recently switched my database from MySQL to PostGres. I am also using GeoKit. When I started my application with a new database already seeded, I get the following error:

PGError: ERROR:  function radians(character varying) does not exist
LINE 1: ...COS(0.661045389762993)*COS(-2.12957994527573)*COS(RADIANS(ti...
                                                         ^
HINT:  No function matches the given name and argument types. You might 
need to add explicit type casts.

      

Does anyone know why this is breaking now? I know GeoKit still works because it still does geocoding in the model per ticket when the database is seeded, it just won't calculate the distances correctly.

+2


a source to share


2 answers


For those looking for this answer in a search, the problem is that Postgresql requires lat, lng columns to be decimal, or at least non-string, whereas MySQL allows both.



+6


a source


Unsurprisingly, the "radians" function expects a DOUBLE PRECISION argument. And there is no value for TEXT / CHARACTER VARYING (aka VARCHAR) for DOUBLE PRECISION.



Probably the simplest solution is to define such a cast.

+2


a source







All Articles