4

I recently switched my database from MySQL to PostGres. I also use GeoKit. When I started my app up with the 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.

Anyone know why this is breaking now? I know GeoKit still works because it's still performing the geocoding in the model per ticket when the database is seeded, it just won't do the distance calculations correctly.

Kevin
  • 1,100
  • 1
  • 11
  • 26

2 Answers2

12

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

Kevin
  • 1,100
  • 1
  • 11
  • 26
  • 1
    Actually, a decimal will not work, it needs to be a float. Decimals support only whole numbers (example: lat,long of -32,117) where as floats support real numbers (example: lat,long of -32.553,117.2342). – sizzle Jul 15 '11 at 08:14
  • Working well with decimals in my app Szielenski. Fully retaining real numbers for lat and lng. – John H Jan 26 '12 at 12:17
2

Unsurprisingly the "radians" function expects a DOUBLE PRECISION argument. And there's no cast defined for TEXT/CHARACTER VARYING (a.k.a. VARCHAR) to DOUBLE PRECISION.

Probably the easiest solution is to define such a cast.

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110