4

I don't know if this has been asked here. I saw couple of questions on "like" operator but I'm not sure if that's I'm looking for. Sorry I'm a noob at this. But I am moving from MySQL to Google App Engine and was wondering if there was an OR operator in GQL similar to ones in MySQL.

Basically what I am trying to achieve is get the login on name via their username or email address. So my query would be something like this.

query = db.GqlQuery("SELECT * FROM mytable 
                     where username = :name 
                     OR email = :email 
                     AND password = :password",
                     name = user,
                     email = email,
                     password = pass1)

I realize that I can perform two queries and check each query for their successful completion and be able to achieve this but I am just wondering if there is already one available in GQL.

Thanks.

shriek
  • 5,605
  • 8
  • 46
  • 75

1 Answers1

3

You can't do OR with GQL; it only supports IN that you can see as a limited form of OR for a specific property.
Like you've already said, your only option is to execute two different queries and combine the results.

If your language of choice is Java, have a look to the Query.CompositeFilter which you can use to construct a filter using the OR operator.

systempuntoout
  • 71,966
  • 47
  • 171
  • 241
  • As a side note: Java Datastore API supports OR as composite operator (meaning it runs multiple queries and combines results under the hood): https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Query.CompositeFilter – Peter Knego Aug 08 '12 at 21:39