@_generative
@_assertions(_no_statement_condition, _no_limit_offset)
def order_by(self, *clauses):
- """Apply one or more ORDER BY criterion to the query and return
+ """Apply one or more ORDER BY criteria to the query and return
the newly resulting :class:`_query.Query`.
- All existing ORDER BY settings can be suppressed by passing
- ``None``.
+ e.g.::
+
+ q = session.query(Entity).order_by(Entity.id, Entity.name)
+
+ All existing ORDER BY criteria may be cancelled by passing
+ ``None`` by itself. New ORDER BY criteria may then be added by
+ invoking :meth:`_orm.Query.order_by` again, e.g.::
+
+ # will erase all ORDER BY and ORDER BY new_col alone
+ q = q.order_by(None).order_by(new_col)
.. seealso::
@_generative
def order_by(self, *clauses):
r"""Return a new selectable with the given list of ORDER BY
- criterion applied.
+ criteria applied.
e.g.::
stmt = select(table).order_by(table.c.id, table.c.name)
+ All existing ORDER BY criteria may be cancelled by passing
+ ``None`` by itself. New ORDER BY criteria may then be added by
+ invoking :meth:`_sql.Select.order_by` again, e.g.::
+
+ # will erase all ORDER BY and ORDER BY new_col alone
+ stmt = stmt.order_by(None).order_by(new_col)
+
:param \*clauses: a series of :class:`_expression.ColumnElement`
constructs
which will be used to generate an ORDER BY clause.