1
votes

I have partition key in azure storage table as below, partition key is string here. for each day, the partition key is Date in string format. if i take count of records based on partiotion key (03042018) and rowkey as (1) . i get 2 counts. 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'

How to pass the partition key as variable in the below query. Here, partitionkey is 'taskseattle', but i want to pass 02042014 on today and when run the python script it should pass 03042018 in the below query in the partitionkey.

a='02042018' (how to pass a in below partition key) tasks = table_service.query_entities('tasktable', "PartitionKey eq 'tasksSeattle'")

1
Just to clarify, you just want to pass the variable a='02042018' instead of the 'tasksSeattle'?Ivan Yang

1 Answers

2
votes

If you just want to pass a variable to the query, please use the code below:

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)

The test result as below: enter image description here