Opened 4 years ago

Closed 4 years ago

Last modified 4 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

Description

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

https://docs.djangoproject.com/en/dev/topics/db/queries/#limiting-querysets

current:
For example, this returns the first 5 objects (LIMIT 5):
>>> Entry.objects.all()[:5]
add:
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 4 years ago by guettli

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

comment:2 Changed 4 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;
1
2
sqlite> 
$ 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 4 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 4 years ago by guettli

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