Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#16698 closed Cleanup/optimization (wontfix)

Docs: QuerySet slicing (SQL LIMIT)

Reported by: guettli Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The current documentation for QuerySet slicing (SQL LIMIT) should be improved:

For example, this returns the first 5 objects (LIMIT 5):
>>> Entry.objects.all()[:5]
No Exception will be raised, if there are fewer results. 
If there are only four entries in the database table, the result will contain four entries.

Change History (4)

comment:1 Changed 5 years ago by guettli

  • Cc hv@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by aaugustin

QuerySets behave consistently with both SQL and Python:

$ sqlite3
sqlite> create table foo (id int);
sqlite> insert into foo (id) values (1);
sqlite> insert into foo (id) values (2);
sqlite> select * from foo limit 5;
$ python
>>> range(4)[:5]
[0, 1, 2, 3]

So the behavior of QuerySets is natural and expected.

In order to keep the docs straightforward, I think it's best to keep the text as is.

comment:3 Changed 5 years ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

I asked on #django-dev, other developers agreed that the current doc is sufficient.

comment:4 Changed 5 years ago by guettli

  • Cc hv@… removed
Note: See TracTickets for help on using tickets.
Back to Top