我该如何使用python将字符串变量传递到GQL中?我可以在SQL中做到这一点,但它无法正常工作。这是我所拥有的:
personalposts = db.GqlQuery("select * from PersonalPost where user_id = %s order by created desc limit 30" % user_id)
这一直使我丧命,但我觉得应该很简单。
谢谢!
最佳答案
这应该工作:
personalposts = db.GqlQuery("select * from PersonalPost where user_id =:1 order by created desc limit 30",user_id)
GqlQuery
语法示例:q = GqlQuery("SELECT * FROM Song WHERE composer = 'Lennon, John'")
q = GqlQuery("SELECT __key__ FROM Song WHERE composer = :1", "Lennon, John")
q = GqlQuery("SELECT * FROM Song WHERE composer = :composer", composer="Lennon, John")
来源: https://developers.google.com/appengine/docs/python/datastore/gqlqueryclass
关于python - 将字符串变量传递到gql查询中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11176084/