2011-06-09 33 views
0

我決定給heroku一個嘗試(以節省時間),但我發現他們使用我知之甚少的PostgreSQL。 geocoder gem在MySQL中效果很好,但是PostgreSQL正在拋出一個錯誤。heroku - postgres - 運營商不存在

我覺得這個錯誤是說拉特沒有定義?

ActiveRecord::StatementInvalid (PGError: ERROR: operator does not exist: numeric - character varying 
LINE 1: ...58.755864232 * 2 * ASIN(SQRT(POWER(SIN((37.358151 - lat) * P... 

完整的日誌

2011-06-07T09:18:52-07:00 heroku[nginx]: GET /api/v1/locations.json?point=37.358151%2C%20-121.628265%20&radius=24.374397 HTTP/1.1 | 66.192.149.18 | 963 | http | 500 
2011-06-07T16:19:12+00:00 app[web.1]: 
2011-06-07T16:19:12+00:00 app[web.1]: 
2011-06-07T16:19:12+00:00 app[web.1]: Started GET "/api/v1/locations.json?point=37.358151%2C%20-121.628265%20&radius=24.374397" for 66.192.149.18 at Tue Jun 07 09:19:12 -0700 2011 
2011-06-07T16:19:12+00:00 app[web.1]: 
2011-06-07T16:19:12+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: operator does not exist: numeric - character varying 
2011-06-07T16:19:12+00:00 app[web.1]: LINE 1: ...58.755864232 * 2 * ASIN(SQRT(POWER(SIN((37.358151 - lat) * P... 
2011-06-07T16:19:12+00:00 app[web.1]:               ^
2011-06-07T16:19:12+00:00 app[web.1]: HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 
2011-06-07T16:19:12+00:00 app[web.1]: : SELECT *, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((37.358151 - lat) * PI()/180/2), 2) + COS(37.358151 * PI()/180) * COS(lat * PI()/180) * POWER(SIN((-121.628265 - lng) * PI()/180/2), 2))) AS distance, CAST(DEGREES(ATAN2(RADIANS(lng - -121.628265), RADIANS(lat - 37.358151))) + 360 AS decimal) % 360 AS bearing FROM "locations" WHERE (lat BETWEEN 37.0053760059938 AND 37.7109259940062 AND lng BETWEEN -122.072086383576 AND -121.184443616424) GROUP BY locations.id,locations.name,locations.bounding_box,locations.created_at,locations.updated_at,locations.street,locations.postal,locations.city,locations.state,locations.country,locations.description,locations.lat,locations.lng,locations.phone,locations.has_lights,locations.is_free,locations.is_outdoors,locations.are_pads_required,locations.has_concrete,locations.has_wood,locations.cd_page_id HAVING 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((37.358151 - lat) * PI()/180/2), 2) + COS(37.358151 * PI()/180) * COS(lat * PI()/180) * POWER(SIN((-121.6 
2011-06-07T16:19:12+00:00 app[web.1]: 28265 - lng) * PI()/180/2), 2))) <= 24.374397 ORDER BY 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((37.358151 - lat) * PI()/180/2), 2) + COS(37.358151 * PI()/180) * COS(lat * PI()/180) * POWER(SIN((-121.628265 - lng) * PI()/180/2), 2))) ASC LIMIT 100): 

回答

1

你需要將其強制轉換:

37.358151 - lat::numeric 
+1

我該怎麼做? – OneChillDude 2013-08-20 23:40:17

1

我有一個類似的錯誤。這是由我在我的遷移中指定的外部id作爲字符串而不是整數。

要解決它,我改變了:

create_table :these_objects do |t| 
    t.string:user_id 
end 

create_table :these_objects do |t| 
    t.integer :user_id 
end 
+0

SQLite在開發過程中從未抱怨過它,但Postgres做過。 – LikeMaBell 2012-01-12 16:24:57

+0

SQLite的類型系統相當寬鬆,PostgreSQL的不是。解決方案是(如您所說)在任何地方和理想情況下使用適當的類型,並在您部署的同一數據庫之上進行開發。 – 2012-01-12 19:00:12

0

我有同樣的問題。 您可能會將您的緯度和經度字段設置爲字符串,因此您需要檢查您的移動文件中是否包含經緯度字段。

create_table :place do |t| 
    t.text :name 
    t.float :latitude 
    t.float :longitude 
    t.timestamps 
end