ah. that makes sense.
here's my working query. returns results in order of distance to a
point (lat,lon):
q = session.query(Student)
j = q.join_to('address')
return q.select(
j,order_by=asc(func.abs(address.c.lat -lat) +
func.abs(address.c.lon-lon))
,limit=500
)
thanks for the response.
...and sqlalchemy.
-brent
On 1/31/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
> use func.abs(q.address.lat) for the ABS function.
>
> On Jan 31, 2007, at 4:24 PM, Brent Pedersen wrote:
>
> >
> > hi, i've got it this far now. but it doesnt like the q.address.lat/lon
> > since it makes an alias in the join. how to i get at that alias?
> >
> >
> > sajoin = q.join_to('address')
> > sorder = "ABS(" + str(q.address.lat) +" - %f) + ABS(" +
> > str(q.address.lon) +" - %f)"
> > sorder %= (lat,lon)
> > return q.select(
> > sajoin
> > ,order_by=asc(sorder)
> > ,limit=800
> > )
> >
> >
> > On 1/31/07, Brent Pedersen <[EMAIL PROTECTED]> wrote:
> >> hi, how can put custom sql in a query? specifically in this code? the
> >> problem is with the order_by. i want to pass it some custom sql:
> >>
> >> q = session.query(Student)
> >> sajoin = q.join_to('address')
> >>
> >> return q.select(
> >> sajoin,
> >> order_by="(ABS(address.lat - %s) + ABS(address.lon - %
> >> s))"
> >> % (lat,lon)
> >> ,limit=800
> >> )
> >>
> >>
> >>
> >> that doesnt work . this does:
> >> order_by=asc((address.c.lat - lat) + (address.c.lon - lon))
> >>
> >> but it's not quite what i need--the manhattan distance....
> >> and i'd like the results to be in my mapped objects so
> >> i can still do
> >> student.address.lat, etc.
> >>
> >> i've scoured the docs, but maybe i've missed something.
> >> any pointers?
> >> thanks.
> >> -brent
> >>
> >
> > >
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---