Re: [sqlalchemy] Computed Columns

2012-10-17 Thread ThereMichael
The distance function should be this: distance_function = ( (6371 * func.acos(func.cos(func.radians(bindparam('origin_lat'))) * func.cos(func.radians(places_table.c.latitude)) * func.cos(func.radians(places_table.c.longitude) -

[sqlalchemy] Computed Columns

2012-10-16 Thread Michael Wilson
Hi, I've like to include the distance of a particular row (object) from a given point in a SQLAlchemy query using the haversine formula, and SORT on the distance, similar to this example: http://stackoverflow.com/questions/574691/mysql-great-circle-distance-haversine-formula But can't figure

Re: [sqlalchemy] Computed Columns

2012-10-16 Thread Ryan Kelly
On Tue, Oct 16, 2012 at 07:06:00AM -0700, Michael Wilson wrote: Hi, I've like to include the distance of a particular row (object) from a given point in a SQLAlchemy query using the haversine formula, and SORT on the distance, similar to this example:

Re: [sqlalchemy] Computed Columns

2012-10-16 Thread ThereMichael
Thanks! Your example worked perfectly. But to simplify the question, I left out a wrinkle. My tables look roughly like this: mapper(Thing, things_table,properties={ 'place_id' : things_table.c.place_id, .. 'place' : relation(Place,

Re: [sqlalchemy] Computed Columns

2012-10-16 Thread Michael Bayer
it's not going to be simple as relationship() doesn't render HAVING, it would have to be embedded in a subquery and then set into the relationship as a secondary table or something similar - this is assuming the lat/long columns in question are on places_table. There are also special recipes

Re: [sqlalchemy] Computed Columns

2012-10-16 Thread ThereMichael
I got it to work. Here's what I did: distance_function = ( 3959 * func.acos(func.cos(func.radians(*bindparam*('origin_lat' * func.cos(func.radians(places_table.c.latitude)) * func.cos(func.radians(places_table.c.longitude) - func.radians(*