Thanks for the reply, Jeremy.

I ultimately got this the following to work.

Chapter.select( :id, :name ).select_append( 
      Sequel.lit( 
        "( 3959 * acos( cos( radians(?) ) * cos( radians( latitude ) ) * 
cos( radians( longitude ) - radians(?) ) + sin( radians(?) ) * sin( 
radians( latitude ) ) ) )", 
        latitude_value, longitude_value, latitude_value ).as( :distance ) 
).order(:distance).limit(5)

On Sunday, April 7, 2013 6:04:44 PM UTC-7, Jeremy Evans wrote:
>
> On Sunday, April 7, 2013 5:19:24 PM UTC-7, Gabriel Correa wrote:
>
>> Hello,
>>
>> I'm new to Sequel and having trouble getting it to produce the following 
>> SQL.
>>
>> SELECT id, name, ( 3959 * acos( cos( radians(PLACEHOLDER) ) * cos( 
>> radians( latitude ) ) * cos( radians( longitude ) - radians(PLACEHOLDER) ) 
>> + sin( radians(PLACEHOLDER) ) * sin( radians( latitude ) ) ) ) as distance 
>> from chapters order by distance
>>
>
> I'm not sure if I got all the parens right, but something like this should 
> work:
>
>   DB[:chapters].
>     select{[:id, :name, (Sequel.expr(3959) * 
> acos(cos(radians(PLACEHOLDER)) * cos(radians(latitude))) * 
> cos(radians(longitude) - radians(PLACEHOLDER)) + sin(radians(PLACEHOLDER)) 
> * sin(radians(latitude))).as(:distance)]}.
>     order(:distance)
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to