On Jan 9, 3:02 pm, Aman Gupta <[email protected]> wrote: > I actually did this the other day in Sequel, albiet very messily: > > EARTH_RADIUS = 3963.19 > DISTANCE = %| > ( > > ACOS(LEAST(1,COS(RADIANS(%s))*COS(RADIANS(%s))*COS(RADIANS(lat))*COS(RADIANS(lng))+ > COS(RADIANS(%s))*SIN(RADIANS(%s))*COS(RADIANS(lat))*SIN(RADIANS(lng))+ > SIN(RADIANS(%s))*SIN(RADIANS(lat))))*#{EARTH_RADIUS} > ) AS distance > | > > def self.find_closest_within_100_miles(lat, lng) > select('*'.lit, (DISTANCE % [lat, lng, lat, lng, > lat]).lit).having(:distance < 100).order(:distance.asc).first > end > > Is there a better way to interpolate in the select part of the > statement, like you can with ? in the where clause.
Using a hash with a placeholder literal string was added a few versions back: 'x = :a'.lit(:a=>1) And .lit has accepted standard placeholders for a while: 'x = ?'.lit(1) I leave the rest to you. :) Jeremy
-- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
