Skip to content

Commit 0b614fa

Browse files
author
Chris Turner
committed
03-Fetch_lang1.rst: readjust additional order_by examples added in 695f656
1 parent ae23695 commit 0b614fa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

docs-parts/queries/03-Fetch_lang1.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ To sort the result, use the ``order_by`` keyword argument.
4242

4343
.. code-block:: python
4444
45+
# ascending order:
4546
data = query.fetch(order_by='name')
47+
# descending order:
48+
data = query.fetch(order_by='name desc')
49+
# by name first, year second:
50+
data = query.fetch(order_by=('name desc', 'year'))
51+
# sort by the primary key:
52+
data = query.fetch(order_by='KEY')
53+
# sort by name but for same names order by primary key:
54+
data = query.fetch(order_by=('name', 'KEY desc'))
4655
4756
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.
4857

@@ -61,10 +70,6 @@ For example, one could do the following:
6170
.. code-block:: python
6271
6372
data = query.fetch(order_by='name', limit=10, offset=5)
64-
data = query.fetch(order_by='name desc') # sort in descending order
65-
data = query.fetch(order_by=('name desc', 'year')) # by name first, year second
66-
data = query.fetch(order_by='KEY') # sort by the primary key
67-
data = query.fetch(order_by=('name', 'KEY desc')) # sort by name but for same names order by primary key
6873
6974
Usage with Pandas
7075
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)