0

It's a zip code search that's working fine in development using mysql but when deployed to heroku it's blowing up.

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)
1
  • You may already know this, but my experience with these kinds of issues was greatly alleviated by developing against Postgres locally Commented Aug 5, 2013 at 20:42

2 Answers 2

1

It was the double negative that was causing issues with postgres. Placing the co-ordinates in brackets has fixed the problem.

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)
Sign up to request clarification or add additional context in comments.

Comments

0

I think you have an extra closing paren at the end. Here is the code formatted so closing parens are generally aligned with the opening 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.

I do not know why MySQL would process this but Postgres would not, however. Perhaps the paren was added accidentally when switching servers.

1 Comment

Sorry, that's a typo on my end. The additional closing bracket isn't there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.