Skip to content

Commit f277c7e

Browse files
Chris Turnerdimitri-yatsenko
andauthored
Update docs-parts/queries/03-Fetch_lang1.rst
Co-authored-by: Dimitri Yatsenko <[email protected]>
1 parent 0755f4c commit f277c7e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs-parts/queries/03-Fetch_lang1.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ To sort the result, add the additional ``order_by`` argument to ``fetch`` .
4444
4545
data = query.fetch(order_by='name')
4646
47-
The ``order_by`` argument is passed directly to SQL and follows the same syntax as the `ORDER BY clause <https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html>`_
47+
The ``order_by`` argument can be a string specifying the attribute to sort by. By default the sort is in ascending order. Use ``'attr desc'`` to sort in descending order by attribute ``attr``. The value can also be a sequence of strings, in which case, the sort performed on all the attributes jointly in the order specified.
48+
49+
The special attribute name ``"KEY"`` represents the primary key attributes in order that they appear in the index. Otherwise, this name can be use as any other argument.
50+
51+
If an attribute happens to be an SQL reserved word, it needs to be enclosed in backquotes. For example
52+
...code: python
53+
data = query.fetch(order_by='`select` desc')
54+
55+
The `order_by` value is eventually passed to the ``ORDER BY`` clause <https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html>`_
4856

4957
Similarly, the ``limit`` and ``offset`` arguments can be used to limit the result to a subset of entities.
5058

0 commit comments

Comments
 (0)