2009-09-02 5 views
1

방금 ​​앱을 위해 레일스로 geokit을 가지고 놀았습니다. 나는 건물입니다. 지오 코딩 된 내 레코더를 가지고 있지만 그때 가서 내가 할 수있는 일을보기 위해 콘솔에 가면 가 다음과 같이 표시됩니다. 사용자가 내 데이터베이스에서 위도와 경도가있는 사용자 개체입니다.왜 이런 식으로 Geokit으로 PostgreSQL이 실패합니까?

>> 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은 불행히도 내 오류 메시지를 검색하려고 시도했을 때 도움말을 찾지 못했습니다.

+0

"레스토랑"테이블의 정의가 보입니까? –

답변

5

마이 그 레이션 중에는 플로트 대신에 restaurants.lat 및 restaurants.lng을 문자열 (문자 변화)로 만들었을 것입니다. Postgres는이를 캐스팅하지 않습니다. 열 유형을 변경하면 괜찮을 것입니다.

관련 문제