0

这是一个邮政编码搜索,在使用 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)
4

2 回答 2

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)
于 2013-08-04T20:32:31.673 回答
0

我认为你最后有一个额外的关闭括号。这是格式化的代码,因此关闭括号通常与开始括号对齐:

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 不会。也许在切换服务器时意外添加了括号。

于 2013-08-04T14:28:43.690 回答