Wasim Thabraze
Wasim Thabraze

Reputation: 810

How do I execute this query in GQL [Google App engine]?

I have a table of projects with two of it's columns as 'language' and 'tag'.

After the user gives an input, I want to output all the projects whose language is input or tag is input.

Sql query for above would be this,

Sql query: Select * from TableName where language='input' OR tag='input'

I tried to execute the same in Gql but in vain. What should be the query in Gql to output the data in the above mentioned way.

Upvotes: 0

Views: 214

Answers (2)

Pere Martra
Pere Martra

Reputation: 36

I don't know if is mandatory for you to use GQL, but in case you are able to avoid it, you can use the ndb filter instead.

results = TableName.query(ndb.OR(TableName.language == 'input',
                       TableName.tag == 'input'))
for result in results: 
    ....your code here...

More information in: https://cloud.google.com/appengine/docs/python/ndb/queries

Upvotes: 1

Igor Artamonov
Igor Artamonov

Reputation: 35961

GQL doesn't have OR, so basically you have to make two separate queries and union results:

Select * from TableName where language='input'
Select * from TableName where tag='input'

You should join results on your app side, Cloud Console doesn't support such things too.

See GQL reference: https://cloud.google.com/datastore/docs/apis/gql/gql_reference

Upvotes: 1

Related Questions