使用 Python SDK 按 RowKey 和 StartsWith 过滤 Azure Table 存储
Filter Azure Table Storage by RowKey and StartsWith using the Python SDK
我看到 Azure Table 存储支持通过部分 RowKey
(除了 PartitionKey
)查询记录(C# 示例 here)。
但是,我在有关过滤查询结果的实际文档中找不到与此相关的任何内容 (here)。
我正在尝试使用 Python Azure-Storage SDK 查询 PartitionKey
和 RowKey
组合的子集,其中 RowKey
以某个字符串开头。我有代码(有效,但不能正确过滤任何行键):
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)
但是,我无法弄清楚向过滤器添加部分 (startswith
) 约束的语法。
有没有人有通过部分 RowKey
字符串过滤 Azure Table 存储查询的经验? 我在这里不知所措;但是,似乎可以通过上面示例中的 C#
代码实现。
如果有关于如何通过 REST 调用执行此操作的任何额外文档,我可能可以将其转换为 Python 用法。
假设您的 RowKey 值包含单词并且您只想过滤以 a
和 b
开头的单词,这就是您要添加到查询中的内容:
(RowKey ge 'a' and RowKey lt 'c') ==> (RowKey >= 'a' && RowKey < 'c')
所以你的代码应该是这样的:
entities = table_service.query_entities('mystoragetable', filter="PartitionKey eq 'mypartitionkey' and RowKey ge '<starts with substring>'", num_results=10)
我看到 Azure Table 存储支持通过部分 RowKey
(除了 PartitionKey
)查询记录(C# 示例 here)。
但是,我在有关过滤查询结果的实际文档中找不到与此相关的任何内容 (here)。
我正在尝试使用 Python Azure-Storage SDK 查询 PartitionKey
和 RowKey
组合的子集,其中 RowKey
以某个字符串开头。我有代码(有效,但不能正确过滤任何行键):
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)
但是,我无法弄清楚向过滤器添加部分 (startswith
) 约束的语法。
有没有人有通过部分 RowKey
字符串过滤 Azure Table 存储查询的经验? 我在这里不知所措;但是,似乎可以通过上面示例中的 C#
代码实现。
如果有关于如何通过 REST 调用执行此操作的任何额外文档,我可能可以将其转换为 Python 用法。
假设您的 RowKey 值包含单词并且您只想过滤以 a
和 b
开头的单词,这就是您要添加到查询中的内容:
(RowKey ge 'a' and RowKey lt 'c') ==> (RowKey >= 'a' && RowKey < 'c')
所以你的代码应该是这样的:
entities = table_service.query_entities('mystoragetable', filter="PartitionKey eq 'mypartitionkey' and RowKey ge '<starts with substring>'", num_results=10)