无法从Azure存储表中获取超过1000行

时间:2018-11-29 06:22:02

标签: python-3.x azure-table-storage

我是Python的初学者,请尝试从azure存储表中检索所有行(超过1000行)。下面是示例代码。 该代码为我提供了1000条记录,但表(testtable)的行数超过50000.i在某些博客中使用延续令牌读取可以提取所有记录。让我知道我该如何实现

table='testtable'
now2='14042018'
count=0

try:
  table_service = TableService(account_name=myaccount, account_key=mykey)
  logging.info('connected successfully')

except Exception as e:
  logging.error(e)



tasks = table_service.query_entities(table,filter='PartitionKey eq \'' + now2 + '\'')

for task in tasks:
  count=count+1
  a=task.desc
  #print(a)
print(count)

1 个答案:

答案 0 :(得分:0)

更新

即使我仅使用以下代码行:

entities = table_service.query_entities(table,filter='PartitionKey eq \'' + now2 + '\'')

并且可以提取表中的所有行(超过10000行)。


使用以下代码:

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')

table='tasktable'
now2='03042018'
count=0       

next_pk=None
next_rk = None

while True:
    entities = table_service.query_entities(table,filter='PartitionKey eq \'' + now2 + '\'')
    for entity in entities:
        count=count+1

    if hasattr(entities, 'x_ms_continuation'):
        x_ms_continuation = getattr(entities, 'x_ms_continuation')
        next_pk = x_ms_continuation['nextpartitionkey']
        next_rk = x_ms_continuation['nextrowkey']
    else:
        break

print(count)

测试结果如下: enter image description here