Opened 18 years ago
Closed 17 years ago
#2150 closed enhancement (fixed)
slicing to the end of a QuerySet
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | normal | Keywords: | qs-rf-fixed |
Cc: | gary.wilson@…, ferringb@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently, when trying to slice to the end of a QuerySet, an AssertionError is raised:
>>>Foo.objects.all()[3:] Traceback (most recent call last): File "<console>", line 1, in ? File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 88, in __repr__ return repr(self._get_data()) File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 412, in _get_data self._result_cache = list(self.iterator()) File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 162, in iterator select, sql, params = self._get_sql_clause() File "/usr/lib/python2.4/site-packages/django/db/models/query.py", line 490, in _get_sql_clause assert self._offset is None, "'offset' is not allowed without 'limit'" AssertionError: 'offset' is not allowed without 'limit'
However, returning rows from an offset to the end of a result set does seem possible...
in MySQL (>=3.23)
"To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:"
http://dev.mysql.com/doc/refman/4.1/en/select.html
SELECT * FROM tbl LIMIT 95,18446744073709551615;
and in PostgreSQL (>=7.3)
"LIMIT ALL is the same as omitting the LIMIT clause."
http://www.postgresql.org/docs/7.3/static/queries-limit.html
SELECT select_list FROM table_expression [LIMIT { number | ALL }] [OFFSET number]
Change History (7)
comment:1 by , 18 years ago
Cc: | added |
---|
comment:2 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 17 years ago
Cc: | added |
---|
comment:4 by , 17 years ago
Keywords: | qs-rf added |
---|---|
Triage Stage: | Design decision needed → Accepted |
comment:5 by , 17 years ago
comment:6 by , 17 years ago
Keywords: | qs-rf-fixed added; qs-rf removed |
---|
comment:7 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [7477]) Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
(In [7147]) queryset-refactor: Implemented slicing to end of querysets.
Refs #2150, #5012.