Re: How do I write a fetch request that will get the entity with the max value?
Re: How do I write a fetch request that will get the entity with the max value?
- Subject: Re: How do I write a fetch request that will get the entity with the max value?
- From: Scott Ellsworth <email@hidden>
- Date: Mon, 1 Aug 2005 19:03:19 -0700
On Aug 1, 2005, at 6:26 PM, Charilaos Skiadas wrote:
On Aug 1, 2005, at 7:42 PM, Scott Ellsworth wrote:
Hi, all.
My World entity has pop and tech int16 attributes. I want to find
the Entity with the largest value of pop+tech/3.
I have read through the NSPredicate BNF doc until I am blue in the
face, but the xcode data modeler does not like anything I have
thrown at it. How do I find the World with the largest value for
pop+tech/3?
The obvious "max(pop+tech/3)" does not work, though weird ones
like "max(pop+tech/3)>7 do not throw a syntax error. It is not
the query I want to do, but it does not throw a syntax error.
I might be completely off the mark here, but anyway these are my 5c:
Well, your query needs to be such that the answer is either a YES
or a NO. In the second case, you are asking it to compute pop+tech/
3, this one value, then take the max of the set consisting of this
one value, which is itself, and then answer YES or NO according to
whether this is bigger or smaller than 7.
I had to rethink it - rather than asking for a value, I needed
something with a YES or NO answer. A wee bit of subtraction, and I
had it:
Once the query is rewritten as (max(pop+tech/3)-pop-tech/3 < 0.01) or
some such, it is quite possible for a sql optimizer or a straight
iterator to run the calculation in a reasonable time, for up to
thousands of items. Apple's Core Data implementation does not do it,
of course, as they do not pass expressions through for functions like
ABS or MAX, but the underlying store can do it.
Your suggestion of precomputing would also work, and I might go that
way instead, as then I am not dependent on Apple implementing the
parser any time soon.
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden