I wonder if people do timings for the variances between a function in the DB vs Python? Unless your queries are so small (like individual records) that a round-trip to the DB is impacted by network lag, I find it's almost always faster to ask the DB to do as much of the lifting as possible.
The downside, of course, is that your code potentially becomes unreadable, harder to migrate between database backends, and more difficult to debug.