为什么 Postgresql 会像这样使用 Geokit 失败? [英] Why does Postgresql fail with Geokit like this?

查看:74
本文介绍了为什么 Postgresql 会像这样使用 Geokit 失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用带有 Rails 的 geokit 来开发我的应用程序建造.我已经对我的唱片进行了地理编码,但是当我去的时候进入控制台看看我能用它做什么然后它爆炸了加上以下内容:用户是一个用户对象,来自我的 lat 和 lng数据库

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

推荐答案

在您的迁移过程中,您可能将 restaurant.lat 和 restaurant.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.

这篇关于为什么 Postgresql 会像这样使用 Geokit 失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆