Re: Support Negative Indexing on QuerySets

2013-08-01 Thread Tom Evans
On Thu, Aug 1, 2013 at 10:44 AM, Loic Bistuer wrote: > On Aug 1, 2013, at 4:05 PM, Tom Evans wrote: > >> qs = ... >> print len(qs) >> print qs[0] >> print qs[-1] >> print qs[0] >> >> How many queries for this? > > Just one and "qs[-1]" will

Re: Support Negative Indexing on QuerySets

2013-08-01 Thread Loic Bistuer
On Aug 1, 2013, at 4:05 PM, Tom Evans wrote: > qs = ... > print len(qs) > print qs[0] > print qs[-1] > print qs[0] > > How many queries for this? Just one and "qs[-1]" will return the last element of the cached result. I'm not trying to be pedantic, I'm just pointing

Re: Support Negative Indexing on QuerySets

2013-08-01 Thread Tom Evans
On Wed, Jul 31, 2013 at 7:39 PM, Loic Bistuer wrote: > In your example "print qs[0]" evaluates a *clone* of "qs", not "qs" itself. > > Therefore "qs[0]; qs[-1]; qs[0]" triggers 3 queries, just like "qs[0]; qs[0]; > qs[0]" would. > Fine, be pedantic: qs = ... print

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Michael Manfre
Is that from django-pyodbc or a very old version of django-mssql? The recent versions of django-mssql use SELECT ROW_NUMBER() OVER (...) to avoid some of the issues with flipping the order multiple times. The biggest issue is that order is not guaranteed without explicitly specifying the order

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Ian Kelly
On Tue, Jul 30, 2013 at 4:04 PM, Wim Lewis wrote: > > On 30 Jul 2013, at 2:06 PM, Florian Apolloner wrote: >> How do you think such support would look like? For negative indices you'd >> have to know the size of the resultset to be able to do "limit somthing >> offset

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Richard Laager
On Wed, 2013-07-31 at 13:01 +0100, Simon Riggs wrote: > 3) retrieve via DESC, apply LIMIT and then re-sort by ASC using derived table ... > (3) would require two sorts on the data like this > > SELECT * FROM (rest-of-query ORDER BY ... DESC LIMIT n ) ORDER BY ... ASC I haven't followed this

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Loic Bistuer
In your example "print qs[0]" evaluates a *clone* of "qs", not "qs" itself. Therefore "qs[0]; qs[-1]; qs[0]" triggers 3 queries, just like "qs[0]; qs[0]; qs[0]" would. Now, if you really evaluate your "qs", for example by doing "list(qs)", then further slicing/indexing on "qs" would operate on

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Tom Evans
On Tue, Jul 30, 2013 at 11:04 PM, Wim Lewis wrote: > > On 30 Jul 2013, at 2:06 PM, Florian Apolloner wrote: >> How do you think such support would look like? For negative indices you'd >> have to know the size of the resultset to be able to do "limit somthing >> offset

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Andre Terra
On Wed, Jul 31, 2013 at 6:54 AM, Daniele Procida wrote: > On Tue, Jul 30, 2013, Andre Terra wrote: > > >As for the reasons for disallowing negative indexes, dcramer's comment in > >the ticket makes it clear: there is no way to infer what the last item in

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Simon Riggs
On 31 July 2013 07:56, Florian Apolloner wrote: > Hi Wim, > > > On Wednesday, July 31, 2013 12:04:42 AM UTC+2, Wim Lewis wrote: >> >> On 30 Jul 2013, at 2:06 PM, Florian Apolloner wrote: >> > How do you think such support would look like? For negative indices >> > you'd

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Daniele Procida
On Tue, Jul 30, 2013, Andre Terra wrote: >As for the reasons for disallowing negative indexes, dcramer's comment in >the ticket makes it clear: there is no way to infer what the last item in a >query would be, except if you order it descendingly. For what is worth,

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Florian Apolloner
Hi Wim, On Wednesday, July 31, 2013 12:04:42 AM UTC+2, Wim Lewis wrote: > > On 30 Jul 2013, at 2:06 PM, Florian Apolloner wrote: > > How do you think such support would look like? For negative indices > you'd have to know the size of the resultset to be able to do "limit > somthing offset

Re: Support Negative Indexing on QuerySets

2013-07-31 Thread Florian Apolloner
On Wednesday, July 31, 2013 1:03:31 AM UTC+2, Andre Terra wrote: > > On Tue, Jul 30, 2013 at 6:55 PM, Florian Apolloner > > wrote: > >> Right, it depends on your usecase; I was just trying to point out other >> alternatives aside from the ones mentioned on the ticket. > >

Re: Support Negative Indexing on QuerySets

2013-07-30 Thread Andre Terra
On Tue, Jul 30, 2013 at 6:55 PM, Florian Apolloner wrote: > Right, it depends on your usecase; I was just trying to point out other > alternatives aside from the ones mentioned on the ticket. I'm sorry if I seemed arrogant in my post. I most definitely did not intend it,

Re: Support Negative Indexing on QuerySets

2013-07-30 Thread Wim Lewis
On 30 Jul 2013, at 2:06 PM, Florian Apolloner wrote: > How do you think such support would look like? For negative indices you'd > have to know the size of the resultset to be able to do "limit somthing > offset length-your_negative_index" -- this doesn't seem to make any sense for > an ORM.

Re: Support Negative Indexing on QuerySets

2013-07-30 Thread Florian Apolloner
On Tuesday, July 30, 2013 11:34:18 PM UTC+2, Andre Terra wrote: > > On Tue, Jul 30, 2013 at 6:06 PM, Florian Apolloner > > wrote: > >> You can always do list(qs)]:-1] though… > > > Although you really shouldn't [1]. Right, it depends on your usecase; I was just trying to

Re: Support Negative Indexing on QuerySets

2013-07-30 Thread Andre Terra
On Tue, Jul 30, 2013 at 6:06 PM, Florian Apolloner wrote: > You can always do list(qs)]:-1] though… Although you really shouldn't [1]. As for the reasons for disallowing negative indexes, dcramer's comment in the ticket makes it clear: there is no way to infer what the

Re: Support Negative Indexing on QuerySets

2013-07-30 Thread Florian Apolloner
Hi Mark, How do you think such support would look like? For negative indices you'd have to know the size of the resultset to be able to do "limit somthing offset length-your_negative_index" -- this doesn't seem to make any sense for an ORM. You can always do list(qs)]:-1] though… Cheers,

Support Negative Indexing on QuerySets

2013-07-30 Thread Mark Young
In this support ticket (https://code.djangoproject.com/ticket/13089), the original closer said "This is a long-standing explicit design decision in the ORM, and so gets a wontfix...". What is the reasoning behind this? Why is negative indexing of querysets disallowed? Thanks! -- You received