GQL Query issue

292 views
Skip to first unread message

fdezjose

unread,
Aug 28, 2008, 3:07:58 PM8/28/08
to Google App Engine
Hello! I'm new in the App Engine world and I've run into an issue
that's driving me crazy. I need to compare two properties (ex.
propertyA > 4 AND propertyB > 8) But by doing that I've discovered
that only one property per query may have inequality filters... Any
suggestion or workaround to be able to accomplish this task?



Thanks!

José Luis
Message has been deleted
Message has been deleted
Message has been deleted

Nevin Freeman

unread,
Aug 28, 2008, 4:17:50 PM8/28/08
to Google App Engine
José,

Many different workarounds are available, depending on your
circumstances. The simplest (not ideal) thing to do would be to run
two queries and then take the intersection of the two results, i.e.:

q1 = Model.gql("WHERE prop1 < :1", number1)
q2 = Model.gql("WHERE prop2 > :1", number2)

batch1 = q1.fetch(1000)
batch2 = q2.fetch(1000)
result = []

for entity in batch1:
if entity in batch2:
result.append(entity)

return result


If you give us a little more context, maybe people who have similar
situations can share with you how they have dealt with the limitation.
In my case, I had to change the way I store my data so that I can get
the right results with only one inequality operator per query (but
name equality operators).

Nevin
Message has been deleted

Nevin Freeman

unread,
Aug 28, 2008, 4:26:49 PM8/28/08
to Google App Engine
From: http://code.google.com/appengine/docs/datastore/queriesandindexes.html

"The query mechanism relies on all results for a query to be adjacent
to one another in the index table, to avoid having to scan the entire
table for results. A single index table cannot represent multiple
inequality filters on multiple properties while maintaining that all
results are consecutive in the table."

Nevin

On Aug 28, 1:23 pm, Davide Rognoni <davide.rogn...@gmail.com> wrote:
> Why this limitation?
Message has been deleted

fdezjose

unread,
Aug 30, 2008, 4:45:30 AM8/30/08
to Google App Engine
I've found a solution to my case. I had to query on two properties:
latitude and longitude, surfing the net I discovered this thing called
Geohash (http://en.wikipedia.org/wiki/Geohash) so now I have a geohash
property that I can query without any problem.

This blog post was also useful:
http://labs.metacarta.com/blog/27.entry/geographic-queries-on-google-app-engine/



Thanks,

José Luis




On Aug 28, 10:33 pm, Davide Rognoni <davide.rogn...@gmail.com> wrote:
> I don't like this "Restrictions on Queries" :-(

Chris

unread,
Oct 21, 2008, 11:17:00 PM10/21/08
to Google App Engine
How do you query date ranges? Say I have an object with a start date
and end date. How do I query objects whose range falls on
date.today()?

On Aug 30, 4:45 am, fdezjose <fdezj...@gmail.com> wrote:
> I've found a solution to my case. I had to query on two properties:
> latitude and longitude, surfing the net I discovered this thing called
> Geohash (http://en.wikipedia.org/wiki/Geohash) so now I have a geohash
> property that I can query without any problem.
>
> This blog post was also useful:http://labs.metacarta.com/blog/27.entry/geographic-queries-on-google-...

Marzia Niccolai

unread,
Oct 22, 2008, 2:11:05 AM10/22/08
to google-a...@googlegroups.com
Hi,

Date ranges shouldn't be a problem, as you can do multiple inequality filters with App Engine, as long as they are on the same property:
http://code.google.com/appengine/docs/datastore/queriesandindexes.html#Restrictions_on_Queries

-Marzia

Chris Spencer

unread,
Oct 22, 2008, 3:53:53 AM10/22/08
to google-a...@googlegroups.com
Thanks. But as I said, I have two properties, a start and end date.

Marzia Niccolai

unread,
Oct 22, 2008, 12:06:13 PM10/22/08
to google-a...@googlegroups.com
In that case, you would not be able to do inequality filters on both dates. You may be able to work around this by storing the start and end date in two separate entities, and referencing one from the other.  Then you can do one inequality filter on the start date, and one on the end date.

-Marzia
Reply all
Reply to author
Forward
0 new messages