Search code examples
google-app-enginegogoogle-cloud-datastore

Go + App Engine Datastore: How to filter out rows that are null?


How do I filter out rows that are null? I know it's hard to find only-null rows, but hopefully this should be easier.

I'd like to do the following:

q := datastore.NewQuery("MY_KIND").Filter("MY_ID !=", nil)

... but Filter doesn't support the != comparator. FYI, using this GQL syntax in the Datastore Viewer works just fine:

SELECT * FROM MY_KIND WHERE MY_ID != NULL

Solution

  • You can use greater filter with the appropriate value (> 0 for numbers, > "" for strings).

    Typically an ID cannot be an empty string or zero.