gpt4 book ai didi

python - 如何使用 python SDK 过滤 Azure 表中的特定行

转载 作者:行者123 更新时间:2023-12-02 07:57:21 25 4
gpt4 key购买 nike

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

PartitionKey      TimeStamp         Name
.. ... ...

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

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

等效的 SQL 查询是

SELECT * from table where NAME LIKE mem%

最佳答案

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

关于python - 如何使用 python SDK 过滤 Azure 表中的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63418215/

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