Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16698 closed Cleanup/optimization (wontfix)

Docs: QuerySet slicing (SQL LIMIT)

Reported by: Thomas Güttler 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 by Thomas Güttler, 13 years ago

Cc: hv@… added

comment:2 by Aymeric Augustin, 13 years ago

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 by Aymeric Augustin, 13 years ago

Resolution: wontfix
Status: newclosed

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

comment:4 by Thomas Güttler, 13 years ago

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