Django

Code

Ticket #2150 (closed: fixed)

Opened 2 years ago

Last modified 3 weeks ago

slicing to the end of a QuerySet

Reported by: Gary Wilson <gary.wilson@gmail.com> Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: qs-rf-fixed Cc: gary.wilson@gmail.com, ferringb@gmail.com
Triage Stage: Accepted Has patch: 0
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

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]

Attachments

Change History

07/20/06 11:17:06 changed by Gary Wilson <gary.wilson@gmail.com>

  • cc set to gary.wilson@gmail.com.

02/15/07 16:08:07 changed by Michael Radziej <mir@noris.de>

  • stage changed from Unreviewed to Design decision needed.

06/03/07 17:37:02 changed by Brian Harring <ferringb@gmail.com>

  • cc changed from gary.wilson@gmail.com to gary.wilson@gmail.com, ferringb@gmail.com.

11/30/07 15:31:24 changed by jacob

  • keywords set to qs-rf.
  • stage changed from Design decision needed to Accepted.

02/22/08 19:34:50 changed by mtredinnick

(In [7147]) queryset-refactor: Implemented slicing to end of querysets.

Refs #2150, #5012.

02/22/08 19:35:57 changed by mtredinnick

  • keywords changed from qs-rf to qs-rf-fixed.

04/26/08 21:50:16 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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


Add/Change #2150 (slicing to the end of a QuerySet)




Change Properties
Action