1

I don't know how i can compare two fields or atributes in GQL.

I use python sdk and i have an object 'Room', this object have two properties one is 'user1' and the other is 'user2' so, i need check when the user connect if him is in a room or not. i want to do something like SQL in GQL like this

SELECT * FROM ROOM WHERE user1 = 'joe' or user2 = 'joe'

but i don't know how do it without OR, because the GQL doesn't work with OR operator.

if somebody can give a simple example of how i can do it, i will be really grateful.

thank you.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Alejandro Mora
  • 157
  • 3
  • 16
  • possible duplicate of [App Engine datastore does not support operator OR](http://stackoverflow.com/questions/930966/app-engine-datastore-does-not-support-operator-or) – Erik Kaplun Oct 01 '13 at 08:56
  • Do you need to check if user1 == user2? Use another pre-computed property to filter by in this case. Denormalization is really useful on gae datastore. Like is_connected = ndb.ComputedProperty(lambda self: self.user1 == self.user2) – Dmytro Sadovnychyi Oct 01 '13 at 11:31

1 Answers1

1

The old Python datastore API (including GQL) does not support OR queries. The new NDP API does support AND and OR queries.

Note that OR queries are not native to datastore: NDB API will issue multiple queries and then combine them in memory to obtain the result.

In GQL the equivalent result would be achieved by running two queries, one for each condition, and then combining the results.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154