简体   繁体   中英

Not able to get more than 1000 rows from azure storage table

I am beginner in Python and try to retrieve all rows (more than 1000 rows) from azure storage table. Below is the sample code. The code gives me 1000 records but the table (testtable) has more than 50000 rows.i read in some blog using continuation token can pull all records. Let me know how can i implement in this

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)

Update :

Even if I just use this line of code:

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

and all of the rows in my table can be fetched(more than 10000 rows).


Use the code below:

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)

Test result as below: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM