[英]Filter Azure Table Storage by RowKey and StartsWith using the Python SDK
I have seen that Azure Table Storage supports querying records by a partial RowKey
(in addition to the PartitionKey
) (C# example here ). 我已经看到Azure Table Storage支持通过部分RowKey
(除了PartitionKey
)查询记录( 此处为 C#示例)。
However, I can't find anything related to this in the actual docs on filtering query results ( here ). 但是,在过滤查询结果的实际文档中,我找不到任何与此相关的内容( 此处 )。
I am trying to using the Python Azure-Storage SDK to query a subset of PartitionKey
and RowKey
combinations where the RowKey
starts with a certain string. 我正在尝试使用Python Azure-Storage SDK查询PartitionKey
和RowKey
组合的子集,其中RowKey
以某个字符串开头。 I have the code (which works, but does not do correct filtering any row keys): 我有代码(可以,但是不能正确过滤任何行键):
from azure.storage.table import TableService
table_service = TableService(account_name=ACCOUNT_NAME, account_key=ACCOUNT_KEY)
entities = table_service.query_entities('mystoragetable', filter='PartitionKey eq mypartitionkey"', num_results=10)
However, I can't figure out the syntax for also adding a partial ( startswith
) constraint to the filter. 但是,我无法弄清楚是否还会向过滤器添加部分( startswith
)约束的语法。
Has anyone had any experience with filtering Azure Table Storage queries by partial RowKey
strings? 有没有人有通过部分RowKey
字符串过滤Azure表存储查询的经验? I am at a loss here; 我在这里不知所措; however, it seems to be possible via the C#
code in the example above. 但是,似乎可以通过以上示例中的C#
代码进行操作。
If there are any extra docs about how to do this via a REST call, I can probably translate that into the Python usage. 如果有关于如何通过REST调用执行此操作的其他文档,我可能可以将其转换为Python用法。
Assuming your RowKey values contains words and you only want to filter the words starting with a
and b
, this is what you would add to your query: 假设您的RowKey值包含单词,并且您只想过滤以a
和b
开头的单词,这就是您要添加到查询中的内容:
(RowKey ge 'a' and RowKey lt 'c') ==> (RowKey >= 'a' && RowKey < 'c')
So your code would be something like: 因此,您的代码将类似于:
entities = table_service.query_entities('mystoragetable', filter="PartitionKey eq 'mypartitionkey' and RowKey ge '<starts with substring>'", num_results=10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.