Querying for entities with missing properties in app engine Datastore?
Asked Answered
I

1

8

I have a model which looks like this:

class Example (db.Model) :
 row_num = db.IntegerProperty(required=True)
 updated = db.IntegerProperty()
 ...
 ...

Now when i store values, I may not fill the value for the updated property every time, which implies that in some entities it may not exist.

I want to construct a datastore query so that i can get all entities of kind Example which do not have the property updated set.

How do i do this?

p.s. i know i can set a default value and then query on it. But the issue is i have over 3 million entities and updated will be marked only for 1% of them, so i do not want to waste so much of datastore space by setting the rest to 0.

Issi answered 26/7, 2010 at 3:44 Comment(0)
H
8

In GQL, objects which do not have a value for a property cannot be returned by queries on that property, so what you're asking for is impossible without a default value.

Reference: section headed "Entities Without a Filtered Property Are Never Returned by a Query" on this page.

Hospice answered 26/7, 2010 at 3:57 Comment(2)
Correct, because anything you try to do that references the non-existent field, will use an index on that field, which will result in the omission of any objects which don't have a value for that field.Hospice
The workaround would be to provide a default value for the updated property, and query for that value.Trierarch

© 2022 - 2024 — McMap. All rights reserved.