2016-01-17 41 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'] 
    ''' 
相关问题