Search code examples
azureazure-storageazure-table-storage

How to filter specific values in Azure Table Storage in a column?


I have column called Id in azure table storage as shown here. I would like to query all the rows that contain 'ActPow'. I understood that I can't use "like" here due to limitation of azure table storage and need to use le and ge for filtering as per documentation. How can I do this for my data? I am using Azure Table Storage SDK for python.


Solution

  • Using Azure Table Storage SDK for python, I've written a python script to retrieve the Name/ID from a table entities by filtering through row key.

    I've taken few row entities from your data table and pass query_entities as shown below:

    Table_Service.query_entities(
    '<tablename>', filter="Name ge 'SH3.PV01.PCS1_1.ActPow' and Name le 'SH6.PV01.PCS1_1.ActPow'")
    

    Try below script which worked for me successfully:

    from  azure.cosmosdb.table.tableservice  import  TableService
    from  azure.cosmosdb.table.models  import  Entity
    Table_Service = TableService(account_name='jahnaviaea0', account_key='gef7M174ISk1jubiZ7bOzP5cXVIU2XjUEm9G5PX4KjXl19JuAmswip2/77Za30FrmBz0CiQtChol+AStDNIGIw==')
    rowouput = Table_Service.query_entities(
    'new', filter="Name ge 'SH3.PV01.PCS1_1.ActPow' and Name le 'SH6.PV01.PCS1_1.ActPow'")
    for  row  in  rowoutput:
    print(row.Name)
    

    Before executing the code, Install the required azure-cosmosdb-table package

    pip install azure-cosmosdb-table
    

    Output:

    enter image description here

    Refer SO by @Ivan Glasenberg & SDK sample tables.