开发者

Python, SQLAlchemy: Query, filter and return value

Say I run a query with a filter,

Session.query(model.Place).join(model.Location).filter(model.Location.great_circle_distance(location) < r)

In order to get the results of this query, it had to have calculated model.Location.great_circle_distance(location). After running this quer开发者_高级运维y, I can get a list of Places which match that criteron of having a great_circle_distance less than r, but, is there any way to return both the result of that calculation and the list of Places that match that query in one fell swoop?


You could use join, column_property and mapper to derive a class that is, essentially, a database view. But unless you intended to use that in more than one place, or the number of rows is huge, I would just do a separate query to get the Location objects and use map to compute the circle distances.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜