gpt4 book ai didi

python - 将字符串变量传递给 gql 查询

转载 作者:太空狗 更新时间:2023-10-29 22:16:35 25 4
gpt4 key购买 nike

到底如何使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com