Python - 如何在 Azure Table 存储中进行范围查询
Python - How to make range queries in Azure Table Storage
我一直在尝试寻找正确的语法来创建从 python 到 Azure Table 存储 table 的范围查询。
继续令牌无法帮助我,因为我想定义一个特定的范围或 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 中使用它。
在您的第一个查询中,您缺少结尾引号:'
。您可能想尝试:
rows = table_service.query_entities( \
tableName, \
"((PartitionKey eq '6' and RowKey gt '1452702466022') and RowKey lt '1452702466422')")
根据我的理解,@minghan 说的是正确的,您的第一个代码是正确的,但在 filter
参数中缺少 end-quote '
。对于第二个代码,select
参数仅为 return 实体的 select 属性 名称,但不要在其中编写条件表达式,如 filter
。
您可以从 Github https://github.com/Azure/azure-storage-python/blob/master/azure/storage/table/tableservice.py, and combine with the section Supported Comparison Operators
of the reference doc Querying Tables and Entities
查看下面函数 table_service.query_entites
的定义
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']
'''
我一直在尝试寻找正确的语法来创建从 python 到 Azure Table 存储 table 的范围查询。
继续令牌无法帮助我,因为我想定义一个特定的范围或 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 中使用它。
在您的第一个查询中,您缺少结尾引号:'
。您可能想尝试:
rows = table_service.query_entities( \
tableName, \
"((PartitionKey eq '6' and RowKey gt '1452702466022') and RowKey lt '1452702466422')")
根据我的理解,@minghan 说的是正确的,您的第一个代码是正确的,但在 filter
参数中缺少 end-quote '
。对于第二个代码,select
参数仅为 return 实体的 select 属性 名称,但不要在其中编写条件表达式,如 filter
。
您可以从 Github https://github.com/Azure/azure-storage-python/blob/master/azure/storage/table/tableservice.py, and combine with the section Supported Comparison Operators
of the reference doc Querying Tables and Entities
table_service.query_entites
的定义
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']
'''