Question

Just recently tried something like the following in the appengine interactive console:

from google.appengine.ext import db
from django.utils import simplejson

class TestDb(db.Model):
    author = db.StringProperty()

def add(name):
    t = TestDb()
    t.author = name
    t.put()
#added some names...
lst = db.GqlQuery("Select * from TestDb")

print [(x.key().id(), x.author) for x in lst]

I know for fact that ID is not sequential, but I assume it will be ascending in order for every new record that comes in.

Now I want to put a condition whose SQL would look something like:

SELECT * FROM TestDb WHERE ID > 2

Is this possible via GqlQuery()?

Was it helpful?

Solution

Automatically assigned IDs are not guaranteed to be sequential, so if you want to rely on ordering your entities you should either assign IDs yourself (which I wouldn't recommend), or sort by another property (perhaps a creation timestamp?)

With that said, you can filter by ID using the special __key__ property. See Key Filters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top