如何使用python SDK筛选Azure表中的特定行

2024-04-25 05:15:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Azure存储表中有以下架构的数据:

PartitionKey      TimeStamp         Name
..                ...               ...

我想返回名称以mem开头的所有实体。我正试图用python实现这一点

我只能在SDK(https://docs.microsoft.com/en-us/rest/api/storageservices/Querying-Tables-and-Entities?redirectedfrom=MSDN)中的filter参数中找到关于进行完整字符串比较的文档。有没有办法进行部分比较

等效的SQL查询是

SELECT * from table where NAME LIKE mem%

Tags: 数据namehttps实体名称comdocs架构
1条回答
网友
1楼 · 发布于 2024-04-25 05:15:13

azure表存储中没有此类运算符

但是有一个技巧(这里是关于这个的blog)你可以用于你的目的。如下所示定义您的$filter:

"Name ge 'mem' and Name lt 'men'"

以下是测试代码(有关更多详细信息,请参阅此doc),工作正常:

from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity

table_service = TableService(account_name='xxx', account_key='xxx')

tasks = table_service.query_entities(
    'your_table_name', filter="Name ge 'mem' and Name lt 'men'")

for task in tasks:
    print(task.Name)

我这边的测试结果:

enter image description here

相关问题 更多 >