Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL generated by Distance::Spherical.to_sql fails on Postgres #12

Closed
dolzenko opened this issue Nov 26, 2010 · 3 comments
Closed

SQL generated by Distance::Spherical.to_sql fails on Postgres #12

dolzenko opened this issue Nov 26, 2010 · 3 comments

Comments

@dolzenko
Copy link

More specifically it fails when calculating distance between similar locations and can be repeated by executing following code:

ActiveRecord::Base.connection.select_value "SELECT #{Graticule::Distance::Spherical.to_sql(:latitude => 51.550249, :latitude_column => 51.550249, :longitude => -0.132918, :longitude_column => -0.132918)}"

returns

ActiveRecord::StatementInvalid: PGError: ERROR: input is out of range

The problem is actually ages old http://rubyforge.org/tracker/index.php?func=detail&aid=17922&group_id=2643&atid=10191 but probably too edge case to be taken care of?

@dolzenko
Copy link
Author

I came up with the following patch (added LEAST(1, ...) to the ACOS argument) https://gist.github.com/716842

@theill
Copy link
Contributor

theill commented Sep 17, 2011

Seems to work great. I've submitted a pull-request with your change to graticule.

@bryckbost
Copy link
Contributor

Fixed in 40541eb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants