Brett
Brett

Reputation: 12007

Finding Google DataStore "not equal to empty string" correct query syntax

I have a Google App Engine project that uses the DataStore for backend data hosting.

I am trying to create a simple query that queries on two properties, one of which is a "not equal" to empty string.

Here is what I am trying to achieve:

query = Race.query(ndb.AND(Race.processing == True, Race.assignment_id != ''))
races = query.fetch(limit)

However, this does not respect the !=. I know from the docs that != is essentially a combination of > and < operators, but I don't know how to apply that to an empty string.

Has someone tried this before? How can I query on two properties, one of which is a "not equals empty string"?:

Upvotes: 2

Views: 1049

Answers (1)

glmvrml
glmvrml

Reputation: 1632

Tried this via my remote API:

> x = User(first_name='test', last_name='')
> x.put()
Key('User', 5965989720096768)
> User.query(User.first_name=='test', User.last_name=='').count()
1
> User.query().count()
219L
> User.query(User.last_name!='').count()
218
> User.query(User.last_name=='').count()
1

Works as expected, double check your empty string is actually not a null value

Upvotes: 4

Related Questions