Rails:从 MySQL 转换为 PostGres 会破坏 Geokit 距离计算吗?
我最近将数据库从 MySQL 切换到 PostGres。我也使用 GeoKit。当我使用已播种的新数据库启动应用程序时,出现以下错误:
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.
有人知道为什么现在会出现这种情况吗?我知道 GeoKit 仍然有效,因为当数据库播种时,它仍然在每张票证的模型中执行地理编码,它只是无法正确执行距离计算。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于那些在搜索中查找此答案的人来说,问题在于 Postgresql 要求 lat、lng 列必须是十进制或至少是非字符串,而 MySQL 允许同时使用两者。
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.
毫不奇怪, "radians" 函数需要一个 DOUBLE PRECISION 参数。并且没有为 TEXT/CHARACTER VARYING(又名 VARCHAR)到 DOUBLE PRECISION 定义强制转换。
也许最简单的解决方案是定义这样的强制转换。
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.