分区键作为 python Azure 存储 table 中的变量

Partition key as variable in python azure storage table

我在 Azure 存储 table 中有分区键,如下所示,这里的分区键是字符串。 对于每一天,分区键都是字符串格式的日期。如果我根据分区键 (03042018) 和行键 (1) 计算记录数。我得到 2 个计数。 partitionkey rowkey timestamp desc 02042018 1 2018-11-26T01:23:57.149Z 'abc' 02042018 1 2018-11-26T23:46:57.149Z 'def' 03042018 1 2018-11-27T01:46:57.149Z 'fff' 03042018 1 2018-11-27T01:47:57.149Z 'ggg' 03042018 2 2018-11-27T01:48:01.149Z 'ggg'

如何在以下查询中将分区键作为变量传递。 在这里,partitionkey 是 'taskseattle',但我想在今天传递 02042014,当 运行 时,python 脚本应该在下面的 partitionkey 查询中传递 03042018。

a='02042018'(如何在下面的分区键中传递 a) 任务 = table_service.query_entities('tasktable', "PartitionKey eq 'tasksSeattle'")

如果您只想将变量传递给查询,请使用以下代码:

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

table_service = TableService(account_name='your_account',account_key='your_key')

a='03042018'
tasks = table_service.query_entities('tasktable',filter='PartitionKey eq \'' + a + '\'')
for task in tasks:
    print(task.description)

测试结果如下: