KEY 列表中包含 __key__ 的 GQL 查询
在 GQL 参考中,建议使用IN
关键字包含值列表,并手动构造一个 Key,GQL 查询
SELECT * FROM MyModel WHERE __key__ = KEY('MyModel', 'my_model_key')
将会成功。但是,使用您期望工作的代码:
SELECT * FROM MyModel WHERE __key__ IN (KEY('MyModel', 'my_model_key1'),
KEY('MyModel', 'my_model_key2'))
在数据存储查看器中,出现“无效的 GQL 查询字符串”的抱怨。
格式化此类查询的正确方法是什么?
更新:当前的 SDK 无法做到这一点。正如我在评论中指出的,使用列表时,只有引用(例如 :1
或 :email
)或 int、float、string、boolean 或 null 文字可接受的列表条目。
第二次更新:我修复了该错误,现在可以执行此类查询。可以在 Google 代码托管 diff.
PS 我知道有更有效的方法可以在 Python 中(无需构建 GQL 查询)并使用remote_api 来执行此操作,但每次调用 remote_api 都会计入配额。在配额不是(必然)免费的环境中,快速和脏查询非常有帮助。
In the GQL reference, it is encouraged to use the IN
keyword with a list of values, and to construct a Key from hand the GQL query
SELECT * FROM MyModel WHERE __key__ = KEY('MyModel', 'my_model_key')
will succeed. However, using the code you would expect to work:
SELECT * FROM MyModel WHERE __key__ IN (KEY('MyModel', 'my_model_key1'),
KEY('MyModel', 'my_model_key2'))
in the Datastore Viewer, there is a complaint of "Invalid GQL query string."
What is the correct way to format such a query?
UPDATE: This is not possible to do with the current SDK. As I note in my comment, when using a list, only a reference (e.g. :1
or :email
) or an int, float, string, boolean or null literal are acceptable list entries.
SECOND UPDATE: I fixed the bug and it is now possible to perform such queries. Fix can be found in Google Code Hosting diff.
PS I know there are more efficient ways to do this in Python (without constructing a GQL query) and using the remote_api, but each call to the remote_api counts against quota. In an environment where quota is not (necessarily) free, quick and dirty queries are very helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白。您的目标是在数据存储查看器中查看特定的实体列表以避免消耗配额?我不知道如何使用 GQL 执行此操作,但如果您知道实体的密钥,则可以直接访问实体,例如:
https://appengine.google.com/datastore/edit?app_id=myapp&key=key1
https://appengine.google.com/datastore/edit?app_id=myapp&key =key2
如果您在代码中执行此操作,请不要尝试使用 GQL。使用 db.get(keys) 或类似的东西。
I don't understand. Your objective is to view a specific list of entities in the Datastore Viewer to avoid consuming quota? I don't know of a way to do this with GQL, but you can access entities directly if you know their key, e.g.:
https://appengine.google.com/datastore/edit?app_id=myapp&key=key1
https://appengine.google.com/datastore/edit?app_id=myapp&key=key2
If you're doing this in code, please don't try use GQL. Use
db.get(keys)
or something similar.修复 是实施后,原始帖子中的代码片段就足够了:
PS我意识到我对原始帖子的评论可能不够清晰,无法作为对未来观众的答案。
After the fix was implemented, the code snippet from the original post will suffice:
PS I realized my comment on the original post may not be sufficiently clear as an answer to future viewers.