开发者

Python, SQLAlchemy: Query, filter and return value

开发者 https://www.devze.com 2023-04-11 05:33 出处:网络
Say I run a query with a filter, Session.query(model.Place).join(model.Location).filter(model.Location.great_circle_distance(location) < r)

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

精彩评论

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