这是一个使用mysql在开发中运行良好的邮政编码搜索,但是当部署到heroku时,它正在爆炸。
ActiveRecord::StatementInvalid (PG::Error: ERROR: syntax error at end of input
LINE 9: <= 6.21371192)
^
: SELECT "zip_codes"."zip_code" FROM "zip_codes" WHERE ((latitude BETWEEN 37.68949912779737
AND 37.869158872202625)
AND (longitude BETWEEN -122.53280459311426
AND -122.30549540688574)
AND sqrt(pow(69.172 *
(latitude-37.779329),2) +
pow(54.67189446319151 *
(longitude--122.41915),2))
<= 6.21371192)
答案 0 :(得分:1)
这是导致postgres问题的双重否定因素。将坐标放在括号中可以解决问题。
SELECT "zip_codes"."zip_code"
FROM "zip_codes"
WHERE ((latitude BETWEEN 37.68949912779737
AND 37.869158872202625)
AND (longitude BETWEEN -122.53280459311426
AND -122.30549540688574)
AND sqrt(pow(69.172 *
(latitude - (37.779329)),2) +
pow(54.67189446319151 *
(longitude - (-122.41915)),2))
<= 6.21371192)
答案 1 :(得分:0)
我认为你最后有一个额外的关闭。这是格式化的代码,因此关闭的parens通常与开头paren对齐:
SELECT "zip_codes"."zip_code"
FROM "zip_codes"
WHERE ((latitude BETWEEN 37.68949912779737 AND 37.869158872202625
) AND
(longitude BETWEEN -122.53280459311426 AND -122.30549540688574
) AND
sqrt(pow(69.172 * (latitude-37.779329),2
) +
pow(54.67189446319151 * (longitude--122.41915),2
)
) <= 6.21371192
))
-------^ this one is extra. Get rid of it.
我不知道为什么MySQL会处理这个,但是Postgres不会。也许在切换服务器时意外添加了paren。