2016-01-17 39 views
0

我被困在試圖找到正確的語法來創建從python到Azure表存儲表的範圍查詢。Python - 如何在Azure表存儲中進行範圍查詢

繼續令牌不能幫助我,因爲我想定義特定的範圍或RowKeys並只檢索那些。

我一直在嘗試以下

rows = table_service.query_entities(
    tableName, 
    "PartitionKey eq '6' and RowKey gt '1452702466022' and RowKey lt '1452702466422") 

rows = table_service.query_entities(
    'rawpowervalues6', "PartitionKey eq '6'", 
    select="RowKey gt '1452702466022' and RowKey lt '1452702466422") 

沒有運氣。我找不到任何關於python範圍查詢的官方文檔。迄今爲止最好的資源是that,但我無法使它在python中工作。

回答

2

在您的第一個查詢中,您缺少結尾引號:'。你可能也想嘗試:

rows = table_service.query_entities(\ 
    tableName, \ 
    "((PartitionKey eq '6' and RowKey gt '1452702466022') and RowKey lt '1452702466422')") 
2

根據我的理解,@minghan說的是正確的,你的第一個代碼是正確的,但在filter參數缺少結束引號'。對於第二個代碼,select參數僅爲返回實體選擇屬性名稱,但不會對其中的條件表達式編碼爲filter

您可以從GitHub https://github.com/Azure/azure-storage-python/blob/master/azure/storage/table/tableservice.py審查了以下功能table_service.query_entites的定義,並與參考文檔的部分Supported Comparison Operators結合Querying Tables and Entities

def query_entities(self, table_name, filter=None, select=None, top=None, 
       next_partition_key=None, next_row_key=None): 
    ''' 
    Get entities in a table; includes the $filter and $select options. 
    table_name: 
     Table to query. 
    filter: 
     Optional. Filter as described at 
     http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx 
    select: 
     Optional. Property names to select from the entities. 
    top: 
     Optional. Maximum number of entities to return. 
    next_partition_key: 
     Optional. When top is used, the next partition key is stored in 
     result.x_ms_continuation['NextPartitionKey'] 
    next_row_key: 
     Optional. When top is used, the next partition key is stored in 
     result.x_ms_continuation['NextRowKey'] 
    ''' 
相關問題