1

私が構築しているアプリの Rails で geokit を使い始めたところです。レコードをジオコーディングしましたが、コンソールに移動して何ができるかを確認すると、次のように爆発しました: 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 

これを解決する方法はありますか?残念ながら、エラーメッセージを検索しようとしたとき、Googleはあまり役に立ちませんでした...

4

1 に答える 1

6

移行では、おそらく、restaurant.lat と restaurants.lng を文字列 (文字はさまざま) として作成しましたが、代わりに浮動小数点数にする必要があります。Postgres はそれをキャストしません。列のタイプを変更すれば問題ありません。

于 2009-09-03T00:12:29.510 に答える