postgresqlで動作しないmysqlクエリがあります:-
@events = Event.all_with_distance([current_user.geo_lat, current_user.geo_lng]).where("start > ?", Time.zone.now).order("distance").order("start DESC").where("title like ?", "%#{params[:q]}%")
def self.all_with_distance(origin)
distance_sql = sql_for_distance(origin)
select("#{table_name}.*, #{distance_sql} AS distance").select("`locations`.`geo_lat`, `locations`.`geo_lng`, `locations`.`name` as location_name").joins(:location).where("#{distance_sql} < 50")
end
これは私が得るエラーです:-
PG::Error: ERROR: syntax error at or near "."
LINE 1: ...SIN(RADIANS(26.8465108)) * SIN(RADIANS(`locations`.`geo_lat`...
生成されたクエリ:-
SELECT events.*, (ACOS( SIN(RADIANS(26.8465108)) * SIN(RADIANS(`locations`.`geo_lat`)) + COS(RADIANS(26.8465108)) * COS(RADIANS(`locations`.`geo_lat`)) * COS(RADIANS(`locations`.`geo_lng`) - RADIANS(80.9466832)) ) * 6378.135) AS distance, `locations`.`geo_lat`, `locations`.`geo_lng`, `locations`.`name` as location_name FROM "events" INNER JOIN "locations" ON "locations"."id" = "events"."location_id" WHERE ((ACOS( SIN(RADIANS(26.8465108)) * SIN(RADIANS(`locations`.`geo_lat`)) + COS(RADIANS(26.8465108)) * COS(RADIANS(`locations`.`geo_lat`)) * COS(RADIANS(`locations`.`geo_lng`) - RADIANS(80.9466832)) ) * 6378.135) < 50) AND (start > '2012-09-21 06:40:18.964016') AND (title like '%%') ORDER BY distance, start DESC