Re: Proposal: QuerySet.exists() method

2007-07-15 Thread Tom Tobin
On 7/15/07, Tai Lee <[EMAIL PROTECTED]> wrote: > > I'd rather petition the PostgreSQL developers to optimise count(*) and > suggest Django users implement their own changes or workaround in the > meantime if they're working with large datasets where count(*) is a > serious performance penalty. Th

Re: Proposal: QuerySet.exists() method

2007-07-15 Thread Tai Lee
I'm also +1 __nonezero__ -1 .exists(). Using .count() already gives us the required functionality and makes logical sense, the only question then is how big of a performance gain do we get by using SELECT 1 LIMIT 1. SELECT 1 FROM [table] LIMIT 1 also feels kinda hackish to me, and I'm guessing it

Re: Proposal: QuerySet.exists() method

2007-07-14 Thread Honza Král
On 7/14/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Fri, 2007-07-13 at 16:22 -0500, Adrian Holovaty wrote: > > I'd like to add a QuerySet.exists() method, which would return True or > > False if the given QuerySet contains at least one record. This would > > be more efficient than qs.c

Re: Proposal: QuerySet.exists() method

2007-07-14 Thread Masida
Although Oracle doesn't have LIMIT, it does have ROWNUM which basically acts as a counter. So I think you should do: SELECT 1 FROM [table] WHERE [where] AND ROWNUM <= 1; When there are JOINS you probably have to put the original SELECT in a subquery of the ROWNUM <= 1 query. More info about ROWN

Re: Proposal: QuerySet.exists() method

2007-07-14 Thread David Larlet
2007/7/14, Gary Wilson <[EMAIL PROTECTED]>: > > James Bennett wrote: > > On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > >> I'm biased, because I have an immediate need for this in a project, > >> but this seems general and useful enough for inclusion in QuerySet. > > > > Implementing the

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Malcolm Tredinnick
On Sat, 2007-07-14 at 13:31 +1000, Malcolm Tredinnick wrote: > On Fri, 2007-07-13 at 16:22 -0500, Adrian Holovaty wrote: > > I'd like to add a QuerySet.exists() method, which would return True or > > False if the given QuerySet contains at least one record. [...] > I'm +0. > > __nonzero__ needs

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Malcolm Tredinnick
On Sat, 2007-07-14 at 00:56 -0400, Leo Soto M. wrote: > On 7/13/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > [...] > > Due to Oracle inclusion, this has to be > > > > select count(*) from [table] where [...] > > > > and then check that the result is > 0, at least in the Oracle ba

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Gary Wilson
James Bennett wrote: > On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: >> I'm biased, because I have an immediate need for this in a project, >> but this seems general and useful enough for inclusion in QuerySet. > > Implementing the check in __nonzero__ and having people test by doing > '

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Leo Soto M.
On 7/13/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: [...] > Due to Oracle inclusion, this has to be > > select count(*) from [table] where [...] > > and then check that the result is > 0, at least in the Oracle backend > (no "limit" extension in Oracle). The problem being that count

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Malcolm Tredinnick
On Fri, 2007-07-13 at 21:56 -0600, Ian Kelly wrote: > > By the way, for all database backends except SQLite, you can implement > > all of this sort of stuff (including exists and __len__) fairly fast > > using cursor.rowcount (the number of rows in the result set). > > Unfortunately, SQLite always

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Ian Kelly
> By the way, for all database backends except SQLite, you can implement > all of this sort of stuff (including exists and __len__) fairly fast > using cursor.rowcount (the number of rows in the result set). > Unfortunately, SQLite always returns -1 for rowcount. I'm building a few > of those opti

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Malcolm Tredinnick
On Fri, 2007-07-13 at 16:22 -0500, Adrian Holovaty wrote: > I'd like to add a QuerySet.exists() method, which would return True or > False if the given QuerySet contains at least one record. This would > be more efficient than qs.count() or len(qs) because it would perform > the following SQL unde

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread James Bennett
On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > I'm biased, because I have an immediate need for this in a project, > but this seems general and useful enough for inclusion in QuerySet. Implementing the check in __nonzero__ and having people test by doing 'if some_queryset' or 'if not so

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Michael Trier
+1 on both. I was needing this just the other day. Michael On 7/13/07, Brian Harring <[EMAIL PROTECTED]> wrote: > > On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > On 7/13/07, SmileyChris <[EMAIL PROTECTED]> wrote: > > > Adrian, I think it's useful enough. But why do you need a .exis

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Brian Harring
On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > On 7/13/07, SmileyChris <[EMAIL PROTECTED]> wrote: > > Adrian, I think it's useful enough. But why do you need a .exists() if > > we could just use __nonzero__ (like Ivan suggested)? > > I hadn't thought of that! Yes, we should definitely im

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Jacob Kaplan-Moss
On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > Yes, we should definitely implement a > QuerySet.__nonzero__() method. However, I'd like there to be an > explicit method (named either exists() or any() or whatever), because [snip] Agreed -- I'm +0 on .exists() and __nonzero__() being an

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Adrian Holovaty
On 7/13/07, SmileyChris <[EMAIL PROTECTED]> wrote: > Adrian, I think it's useful enough. But why do you need a .exists() if > we could just use __nonzero__ (like Ivan suggested)? I hadn't thought of that! Yes, we should definitely implement a QuerySet.__nonzero__() method. However, I'd like there

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread SmileyChris
On Jul 14, 9:55 am, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > Adrian Holovaty wrote: > > I'd like to add a QuerySet.exists() method, which would return True or > > False if the given QuerySet contains at least one record. This would > > be more efficient than qs.count() or len(qs) because it wo

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Ivan Sagalaev
Adrian Holovaty wrote: > I'd like to add a QuerySet.exists() method, which would return True or > False if the given QuerySet contains at least one record. This would > be more efficient than qs.count() or len(qs) because it would perform > the following SQL under the hood: > > SELECT 1 FROM

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Deryck Hodge
On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > I'd like to add a QuerySet.exists() method, which would return True or > False if the given QuerySet contains at least one record. This would > be more efficient than qs.count() or len(qs) because it would perform > the following SQL under

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Frédéric Roland
Why not QuerySet.isEmpty() ? Adrian Holovaty a écrit : > I'd like to add a QuerySet.exists() method, which would return True or > False if the given QuerySet contains at least one record. This would > be more efficient than qs.count() or len(qs) because it would perform > the following SQL under

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Tom Tobin
On 7/13/07, Tom Tobin <[EMAIL PROTECTED]> wrote: > +0; seems like a reasonable addition. I wonder of "any" might be a > better method name (along the lines of the Python 2.5 built-in > function), but either name would be fine IMHO. Err, I wonder *if*. ::sigh:: :-) --~--~-~--~~

Re: Proposal: QuerySet.exists() method

2007-07-13 Thread Tom Tobin
On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > I'd like to add a QuerySet.exists() method, which would return True or > False if the given QuerySet contains at least one record. This would > be more efficient than qs.count() or len(qs) because it would perform > the following SQL under