为什么 Postgresql 使用 Geokit 会失败?
我刚刚开始使用 Geokit 和 Rails 来开发我的应用程序 建筑。我已经对我的记录进行了地理编码,但是当我去的时候 进入控制台看看我能用它做什么,结果爆炸了 添加以下内容: user 是一个用户对象,其中包含我的 lat 和 lng 数据库
>> Restaurant.find(:all, :origin => user)
Restaurant Load (0.0ms) PGError: ERROR: operator does not exist:
numeric - character varying
LINE 1: ...*, SQRT(POW(111.1819*(-33.872517-restauran...
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
: SELECT *, SQRT(POW(111.1819*(-33.872517-restaurants.lat),2)+
POW(76.7136337302943*(151.205536-restaurants.lng),2))
AS distance FROM "restaurants"
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not
exist: numeric - character varying
LINE 1: ...*, SQRT(POW(111.1819*(-33.872517-
restauran...
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
: SELECT *, SQRT(POW(111.1819*(-33.872517-
restaurants.lat),2)+
POW(76.7136337302943*(151.205536-restaurants.lng),
2))
AS distance FROM "restaurants"
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:
212:in `log'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/
postgresql_adapter.rb:538:in `execute'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/
postgresql_adapter.rb:1019:in `select_raw'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/
postgresql_adapter.rb:1006:in `select'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:7:in `select_all_without_query_cache'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
query_cache.rb:62:in `select_all'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/base.rb:661:in `find_by_sql'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/base.rb:1548:in `find_every'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/base.rb:615:in `find'
from /Users/chris/projects/mine/lunchdecider/vendor/plugins/geokit-
rails/lib/geokit-rails/acts_as_mappable.rb:138:in `find'
from (irb):10
有什么想法可以解决这个问题吗?不幸的是谷歌并不多 当我尝试搜索错误消息时提供帮助...
I've just started playing with geokit with Rails for an app I am
building. I have got my recorda getting geocoded, but then when I go
into the console to have a look at what I can do it with and it blew
up with the following: user is a user object with lat and lng from my
database
>> Restaurant.find(:all, :origin => user)
Restaurant Load (0.0ms) PGError: ERROR: operator does not exist:
numeric - character varying
LINE 1: ...*, SQRT(POW(111.1819*(-33.872517-restauran...
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
: SELECT *, SQRT(POW(111.1819*(-33.872517-restaurants.lat),2)+
POW(76.7136337302943*(151.205536-restaurants.lng),2))
AS distance FROM "restaurants"
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not
exist: numeric - character varying
LINE 1: ...*, SQRT(POW(111.1819*(-33.872517-
restauran...
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
: SELECT *, SQRT(POW(111.1819*(-33.872517-
restaurants.lat),2)+
POW(76.7136337302943*(151.205536-restaurants.lng),
2))
AS distance FROM "restaurants"
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:
212:in `log'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/
postgresql_adapter.rb:538:in `execute'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/
postgresql_adapter.rb:1019:in `select_raw'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/
postgresql_adapter.rb:1006:in `select'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
database_statements.rb:7:in `select_all_without_query_cache'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/connection_adapters/abstract/
query_cache.rb:62:in `select_all'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/base.rb:661:in `find_by_sql'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/base.rb:1548:in `find_every'
from /Users/chris/projects/mine/lunchdecider/vendor/rails/
activerecord/lib/active_record/base.rb:615:in `find'
from /Users/chris/projects/mine/lunchdecider/vendor/plugins/geokit-
rails/lib/geokit-rails/acts_as_mappable.rb:138:in `find'
from (irb):10
Any ideas how this can be resolved? Google was unfortunately not much
help when I tried to search my error message ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在迁移过程中,您可能将restaurant.lat 和restaurants.lng 创建为字符串(字符不同),而它们应该是浮点数。 Postgres 不会为你投射它。改变列类型就可以了。
In your migration, you probably created restaurants.lat and restaurants.lng as strings (character varying), when they should be floats instead. Postgres won't cast that for you. Alter the column types and you should be fine.