我在azure存储表中有分区键,如下所示,分区键是字符串。对于每一天,分区键是字符串格式的日期。如果我根据partiotion键(03042018)和rowkey为(1)计算记录数。我得到2个计数。 partitionkey rowkey timestamp desc 02042018 1 2018-11-26T01:23:57.149Z'abc'02042018 1 2018-11-26T23:46:57.149Z'dend'03042018 1 2018-11-27T01:46:57.149Z'ffff'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'(如何在下面的分区键中传递)tasks = table_service.query_entities('tasktable',“PartitionKey eq'assobageSattle'”)
如果您只想将变量传递给查询,请使用以下代码:
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)