Help Center/ GeminiDB/ GeminiDB Cassandra API/ FAQs/ Database Usage/ How Do I Set Paging Query with Python?
Updated on 2024-05-30 GMT+08:00

How Do I Set Paging Query with Python?

Using Paging Query

The fetch size controls how many rows will be fetched per page.

query = "SELECT * FROM space3.table3;"  # table3 contains 100 rows
statement = SimpleStatement(query, fetch_size=10)

After the setting is successful, for all sessions spawned with this configuration, 10 rows are fetched from the server at a time. When the cache (10 rows) is exhausted, the system triggers a request for fetching another 10 rows from the server and there can be a waiting period.

result = session.execute(statement)
# Print the number of current cache rows. The number is 10.
print(result.current_rows)
# The next page is automatically obtained.
for row in result:
    print(row)

Saving and Reusing the Paging State

  1. Save the current paging state.
    # Save the paging status.
    web_session['paging_stage'] = results.paging_state
  2. Load and reuse the current paging state.
    statement = SimpleStatement(query, fetch_size=10)
    ps = web_session['paging_state']
    results = session.execute(statement, paging_state=ps)

    For more advanced usage and introduction, see Paging Large Queries.