Skip to content
Snippets Groups Projects
Commit d00e7e85 authored by alexreisner's avatar alexreisner
Browse files

Fix PostgreSQL bug reported by developish.

Avoid using column aliases in the HAVING clause (not allowed by
PostgreSQL).
parent fdfb29b3
Branches
Tags
No related merge requests found
......@@ -94,18 +94,19 @@ module Geocoder
# generate hash
lat_attr = geocoder_options[:latitude]
lon_attr = geocoder_options[:longitude]
{
:select => "*, 3956 * 2 * ASIN(SQRT(" +
distance = "3956 * 2 * ASIN(SQRT(" +
"POWER(SIN((#{latitude} - #{lat_attr}) * " +
"PI() / 180 / 2), 2) + COS(#{latitude} * PI()/180) * " +
"COS(#{lat_attr} * PI() / 180) * " +
"POWER(SIN((#{longitude} - #{lon_attr}) * " +
"PI() / 180 / 2), 2) )) as distance",
"PI() / 180 / 2), 2) ))"
{
:select => "*, #{distance} AS distance",
:conditions => [
"#{lat_attr} BETWEEN ? AND ? AND " +
"#{lon_attr} BETWEEN ? AND ?",
lat_lo, lat_hi, lon_lo, lon_hi],
:having => "distance <= #{radius}",
:having => "#{distance} <= #{radius}",
:order => options[:order],
:limit => limit
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment