0

How can I select only objects with null values in GQL. I have a object that for a new version of my software I include a LastUpdate fields, and I want to update only the oldest updated object, but when I made the query using " ORDER BY LastUpdate ASC", this query should always be used!, it always return only the objects with some value in LastUpdate.

How the best way I can include in a query the objects with null value?

Victor
  • 8,309
  • 14
  • 80
  • 129

3 Answers3

3

If an entity in the datastore does not have the new attribute set, then it is impossible to query on it.

The entities will not have a null value for the property, the property simply will not exist, therfore will not be included in any indexes that you would use to query your entities. The only way to find your entities that need updating is to map over ALL entities and find the ones with missing values.

Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57
0

How much control do you have over record creation? You could always create a new record with the LastUpdate field set to the same value as the RecordCreated field. That way the field would never be blank and could always be queried.

Disadvantage: you would also pick up records that were created a long time ago and not updated since.

rossum
  • 15,344
  • 1
  • 24
  • 38
  • I have no control. The records were created in older versions from the application. – Victor Jul 13 '11 at 16:58
  • Would it be possible to scan through the database, updating all the records with a null LastUpdated field from the RecordCreated field? – rossum Jul 13 '11 at 18:19
-1

maybe use an NVL wrapper ... NVL( LastUpdate, sysdate )

Randy
  • 16,480
  • 1
  • 37
  • 55
  • I try to query "SELECT * FROM Object ORDER BY NVL(LastUpdate, sysdate) ASC" but I didn't work. – Victor Jul 13 '11 at 14:52
  • NVL is not valid/supported in GQL. http://code.google.com/appengine/docs/python/datastore/gqlreference.html – cope360 Jul 13 '11 at 17:38