On Wed, Feb 28, 2018 at 3:02 PM, <jens.troe...@gmail.com> wrote: > Hello, > > I’m curious about your experience with sorting the results of all() > <http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.all> > queries which return a list. It seems to me that there are three ways of > sorting such result lists: > > 1. Use an ORDER BY > > <http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.order_by> > in the query and let the database do the sorting. > > I would guess that the DB would be the fastest if one were to benchmark sorting speeds. I have not.
> > 1. Use Python’s list.sort() > <https://docs.python.org/3/library/stdtypes.html#list.sort> and sort > the result list in-place. > 2. Use Python’s sorted() > <https://docs.python.org/3/library/functions.html#sorted> function and > construct a new and sorted list from the result list. > > I would guess that both Python sort incantations are of similar performance values. Here is a Stack Overflow thread about sort() vs sorted() https://stackoverflow.com/questions/22442378/what-is-the-difference-between-sortedlist-vs-list-sort-python -m -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.