Why does Postgresql fail with Geokit like this?

£可爱£侵袭症+ 提交于 2019-12-23 02:38:46

问题


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 ...


回答1:


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.



来源:https://stackoverflow.com/questions/1370461/why-does-postgresql-fail-with-geokit-like-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!